Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DateTimeUtils;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
import org.joda.time.field.FieldUtils;
import org.joda.time.field.ImpreciseDateTimeField;
/**
* Provides time calculations for the month of the year component of time.
*
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.2, refactored from GJMonthOfYearDateTimeField
*/
class BasicMonthOfYearDateTimeField extends ImpreciseDateTimeField {
/** Serialization version */
private static final long serialVersionUID = -8258715387168736L;
private static final int MIN = DateTimeConstants.JANUARY;
private final BasicChronology iChronology;
private final int iMax;
private final int iLeapMonth;
/**
* Restricted constructor.
*
* @param leapMonth the month of year that leaps
*/
BasicMonthOfYearDateTimeField(BasicChronology chronology, int leapMonth) {
super(DateTimeFieldType.monthOfYear(), chronology.getAverageMillisPerMonth());
iChronology = chronology;
iMax = iChronology.getMaxMonth();
iLeapMonth = leapMonth;
}
//-----------------------------------------------------------------------
public boolean isLenient() {
return false;
}
//-----------------------------------------------------------------------
/**
* Get the Month component of the specified time instant.
*
* @see org.joda.time.DateTimeField#get(long)
* @see org.joda.time.ReadableDateTime#getMonthOfYear()
* @param instant the time instant in millis to query.
* @return the month extracted from the input.
*/
public int get(long instant) {
return iChronology.getMonthOfYear(instant);
}
//-----------------------------------------------------------------------
/**
* Add the specified month to the specified time instant.
* The amount added may be negative.<p>
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>Chronology.getYear(instant);
if (iChronology.isLeapYear(thisYear)) {
return (iChronology.getMonthOfYear(instant, thisYear) == iLeapMonth);
}
return false;
}
//-----------------------------------------------------------------------
public int getLeapAmount(long instant) {
return isLeap(instant) ? 1 : 0;
}
//-----------------------------------------------------------------------
public DurationField getLeapDurationField() {
return iChronology.days();
}
//-----------------------------------------------------------------------
public int getMinimumValue() {
return MIN;
}
//-----------------------------------------------------------------------
public int getMaximumValue() {
return iMax;
}
//-----------------------------------------------------------------------
public long roundFloor(long instant) {
int year = iChronology.getYear(instant);
int month = iChronology.getMonthOfYear(instant, year);
return iChronology.getYearMonthMillis(year, month);
}
//-----------------------------------------------------------------------
public long remainder(long instant) {
return instant - roundFloor(instant);
}
//-----------------------------------------------------------------------
/**
* Serialization singleton
*/
private Object readResolve() {
return iChronology.monthOfYear();
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> of that field
* @throws IllegalArgumentException if the field type is null
*/
int get(DateTimeFieldType type);
/**
* Checks whether the field type specified is supported by this implementation.
*
* @param field the field type to check, may be null which returns false
* @return true if the field is supported
*/
boolean isSupported(DateTimeFieldType field);
//-----------------------------------------------------------------------
/**
* Get the value as a simple immutable <code>Instant</code> object.
* <p>
* This can be useful if you don't trust the implementation
* of the interface to be well-behaved, or to get a guaranteed
* immutable object.
*
* @return the value as an <code>Instant</code> object
*/
Instant toInstant();
//-----------------------------------------------------------------------
// Method is no longer defined here as that would break generic backwards compatibility
// /**
// * Compares this object with the specified object for ascending
// * millisecond instant order. This ordering is inconsistent with
// * equals, as it ignores the Chronology.
// * <p>
// * All ReadableInstant instances are accepted.
// *
// * @param readableInstant a readable instant to check against
// * @return negative value if this is less, 0 if equal, or positive value if greater
// * @throws NullPointerException if the object is null
// * @throws ClassCastException if the object type is not supported
// */
// int compareTo(ReadableInstant readableInstant);
//-----------------------------------------------------------------------
/**
* Is this instant equal to the instant passed in
* comparing solely by millisecond.
*
* @param instant an instant to check against, null means now
* @return true if the instant is equal to the instant passed in
*/
boolean isEqual(ReadableInstant instant);
/**
* Is this instant after the instant passed in
* comparing solely by millisecond.
*
* @param instant an instant to check against, null means now
* @return true if the instant is after the instant passed in
*/
boolean isAfter(ReadableInstant instant);
/**
* Is this instant before the instant passed in
* comparing solely by millisecond.
*
* @param instant an instant to check against, null means now
* @return true if the instant is before the instant passed in
*/
boolean isBefore(ReadableInstant instant);
//-----------------------------------------------------------------------
/**
* Compares this object with the specified object for equality based
* on the millisecond instant and the Chronology. All ReadableInstant
* instances are accepted.
* <p>
* To compare two instants for absolute time (ie. UTC milliseconds
* ignoring the chronology), use {@link #isEqual(ReadableInstant)} or
* {@link #compareTo(Object)}.
*
* @param readableInstant a readable instant to check against
* @return true if millisecond and chronology are equal, false if
*
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> not or the instant is null or of an incorrect type
*/
boolean equals(Object readableInstant);
/**
* Gets a hash code for the instant that is compatible with the
* equals method.
* <p>
* The formula used must be as follows:
* <pre>
* ((int) (getMillis() ^ (getMillis() >>> 32))) +
* (getChronology().hashCode())
* </pre>
*
* @return a hash code as defined above
*/
int hashCode();
//-----------------------------------------------------------------------
/**
* Get the value as a String in a recognisable ISO8601 format.
* <p>
* The string output is in ISO8601 format to enable the String
* constructor to correctly parse it.
*
* @return the value as an ISO8601 string
*/
String toString();
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> upperLimit = mdt.toDateTime();
}
LimitChronology chrono = getInstance
(getBase().withZone(zone), lowerLimit, upperLimit);
if (zone == DateTimeZone.UTC) {
iWithUTC = chrono;
}
return chrono;
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int millisOfDay)
throws IllegalArgumentException
{
long instant = getBase().getDateTimeMillis(year, monthOfYear, dayOfMonth, millisOfDay);
checkLimits(instant, "resulting");
return instant;
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
long instant = getBase().getDateTimeMillis
(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
checkLimits(instant, "resulting");
return instant;
}
public long getDateTimeMillis(long instant,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
checkLimits(instant, null);
instant = getBase().getDateTimeMillis
(instant, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
checkLimits(instant, "resulting");
return instant;
}
protected void assemble(Fields fields) {
// Keep a local cache of converted fields so as not to create redundant
// objects.
HashMap<Object, Object> converted = new HashMap<Object, Object>();
// Convert duration fields...
fields.eras = convertField(fields.eras, converted);
fields.centuries = convertField(fields.centuries, converted);
fields.years = convertField(fields.years, converted);
fields.months = convertField(fields.months, converted);
fields.weekyears = convertField(fields.weekyears, converted);
fields.weeks = convertField(fields.weeks, converted);
fields.days = convertField(fields.days, converted);
fields.halfdays = convertField(fields.halfdays, converted);
fields.hours = convertField(fields.hours, converted);
fields.minutes = convertField(fields.minutes, converted);
fields.seconds = convertField(fields.seconds, converted);
fields.millis = convertField(fields.millis, converted);
// Convert datetime fields...
fields.year = convertField(fields.year, converted);
fields.yearOfEra = convertField(fields.yearOfEra, converted);
fields.yearOfCentury = convertField(fields.yearOfCentury, converted);
fields.centuryOfEra = convertField(fields.centuryOfEra, converted);
fields.era = convertField(fields.era, converted);
fields.dayOfWeek = convertField(fields.dayOfWeek, converted);
fields.
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>dayOfMonth = convertField(fields.dayOfMonth, converted);
fields.dayOfYear = convertField(fields.dayOfYear, converted);
fields.monthOfYear = convertField(fields.monthOfYear, converted);
fields.weekOfWeekyear = convertField(fields.weekOfWeekyear, converted);
fields.weekyear = convertField(fields.weekyear, converted);
fields.weekyearOfCentury = convertField(fields.weekyearOfCentury, converted);
fields.millisOfSecond = convertField(fields.millisOfSecond, converted);
fields.millisOfDay = convertField(fields.millisOfDay, converted);
fields.secondOfMinute = convertField(fields.secondOfMinute, converted);
fields.secondOfDay = convertField(fields.secondOfDay, converted);
fields.minuteOfHour = convertField(fields.minuteOfHour, converted);
fields.minuteOfDay = convertField(fields.minuteOfDay, converted);
fields.hourOfDay = convertField(fields.hourOfDay, converted);
fields.hourOfHalfday = convertField(fields.hourOfHalfday, converted);
fields.clockhourOfDay = convertField(fields.clockhourOfDay, converted);
fields.clockhourOfHalfday = convertField(fields.clockhourOfHalfday, converted);
fields.halfdayOfDay = convertField(fields.halfdayOfDay, converted);
}
private DurationField convertField(DurationField field, HashMap<Object, Object> converted) {
if (field == null || !field.isSupported()) {
return field;
}
if (converted.containsKey(field)) {
return (DurationField)converted.get(field);
}
LimitDurationField limitField = new LimitDurationField(field);
converted.put(field, limitField);
return limitField;
}
private DateTimeField convertField(DateTimeField field, HashMap<Object, Object> converted) {
if (field == null || !field.isSupported()) {
return field;
}
if (converted.containsKey(field)) {
return (DateTimeField)converted.get(field);
}
LimitDateTimeField limitField =
new LimitDateTimeField(field,
convertField(field.getDurationField(), converted),
convertField(field.getRangeDurationField(), converted),
convertField(field.getLeapDurationField(), converted));
converted.put(field, limitField);
return limitField;
}
void checkLimits(long instant, String desc) {
DateTime limit;
if ((limit = iLowerLimit) != null && instant < limit.getMillis()) {
throw new LimitException(desc, true);
}
if ((limit = iUpperLimit) != null && instant >= limit.getMillis()) {
throw new LimitException(desc, false);
}
}
//-----------------------------------------------------------------------
/**
* A limit chronology is only equal to a limit chronology with the
* same base chronology and limits.
*
* @param obj the
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> object to compare to
* @return true if equal
* @since 1.4
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof LimitChronology == false) {
return false;
}
LimitChronology chrono = (LimitChronology) obj;
return
getBase().equals(chrono.getBase()) &&
FieldUtils.equals(getLowerLimit(), chrono.getLowerLimit()) &&
FieldUtils.equals(getUpperLimit(), chrono.getUpperLimit());
}
/**
* A suitable hashcode for the chronology.
*
* @return the hashcode
* @since 1.4
*/
public int hashCode() {
int hash = 317351877;
hash += (getLowerLimit() != null ? getLowerLimit().hashCode() : 0);
hash += (getUpperLimit() != null ? getUpperLimit().hashCode() : 0);
hash += getBase().hashCode() * 7;
return hash;
}
/**
* A debugging string for the chronology.
*
* @return the debugging string
*/
public String toString() {
return "LimitChronology[" + getBase().toString() + ", " +
(getLowerLimit() == null ? "NoLimit" : getLowerLimit().toString()) + ", " +
(getUpperLimit() == null ? "NoLimit" : getUpperLimit().toString()) + ']';
}
//-----------------------------------------------------------------------
/**
* Extends IllegalArgumentException such that the exception message is not
* generated unless it is actually requested.
*/
private class LimitException extends IllegalArgumentException {
private static final long serialVersionUID = -5924689995607498581L;
private final boolean iIsLow;
LimitException(String desc, boolean isLow) {
super(desc);
iIsLow = isLow;
}
public String getMessage() {
StringBuffer buf = new StringBuffer(85);
buf.append("The");
String desc = super.getMessage();
if (desc != null) {
buf.append(' ');
buf.append(desc);
}
buf.append(" instant is ");
DateTimeFormatter p = ISODateTimeFormat.dateTime();
p = p.withChronology(getBase());
if (iIsLow) {
buf.append("below the supported minimum of ");
p.printTo(buf, getLowerLimit().getMillis());
} else {
buf.append("above the supported maximum of ");
p.printTo(buf, getUpperLimit().getMillis());
}
buf.append(" (");
buf.append(getBase());
buf.append(')');
return buf.toString();
}
public String toString() {
return "IllegalArgumentException: " + getMessage();
}
}
private class LimitDurationField extends DecoratedDurationField {
private static final long serialVersionUID =
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>8049297699408782284L;
LimitDurationField(DurationField field) {
super(field, field.getType());
}
public int getValue(long duration, long instant) {
checkLimits(instant, null);
return getWrappedField().getValue(duration, instant);
}
public long getValueAsLong(long duration, long instant) {
checkLimits(instant, null);
return getWrappedField().getValueAsLong(duration, instant);
}
public long getMillis(int value, long instant) {
checkLimits(instant, null);
return getWrappedField().getMillis(value, instant);
}
public long getMillis(long value, long instant) {
checkLimits(instant, null);
return getWrappedField().getMillis(value, instant);
}
public long add(long instant, int amount) {
checkLimits(instant, null);
long result = getWrappedField().add(instant, amount);
checkLimits(result, "resulting");
return result;
}
public long add(long instant, long amount) {
checkLimits(instant, null);
long result = getWrappedField().add(instant, amount);
checkLimits(result, "resulting");
return result;
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
checkLimits(minuendInstant, "minuend");
checkLimits(subtrahendInstant, "subtrahend");
return getWrappedField().getDifference(minuendInstant, subtrahendInstant);
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
checkLimits(minuendInstant, "minuend");
checkLimits(subtrahendInstant, "subtrahend");
return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant);
}
}
private class LimitDateTimeField extends DecoratedDateTimeField {
private static final long serialVersionUID = -2435306746995699312L;
private final DurationField iDurationField;
private final DurationField iRangeDurationField;
private final DurationField iLeapDurationField;
LimitDateTimeField(DateTimeField field,
DurationField durationField,
DurationField rangeDurationField,
DurationField leapDurationField) {
super(field, field.getType());
iDurationField = durationField;
iRangeDurationField = rangeDurationField;
iLeapDurationField = leapDurationField;
}
public int get(long instant) {
checkLimits(instant, null);
return getWrappedField().get(instant);
}
public String getAsText(long instant, Locale locale) {
checkLimits(instant, null);
return getWrappedField().getAsText(instant, locale);
}
public String getAsShortText(long instant, Locale locale)
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>time.chrono.ZonedChronology
*/
public abstract Chronology withZone(DateTimeZone zone);
/**
* Returns a datetime millisecond instant, formed from the given year,
* month, day, and millisecond values. The set of given values must refer
* to a valid datetime, or else an IllegalArgumentException is thrown.
* <p>
* The default implementation calls upon separate DateTimeFields to
* determine the result. Subclasses are encouraged to provide a more
* efficient implementation.
*
* @param year year to use
* @param monthOfYear month to use
* @param dayOfMonth day of month to use
* @param millisOfDay millisecond to use
* @return millisecond instant from 1970-01-01T00:00:00Z
*/
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int millisOfDay)
throws IllegalArgumentException
{
long instant = year().set(0, year);
instant = monthOfYear().set(instant, monthOfYear);
instant = dayOfMonth().set(instant, dayOfMonth);
return millisOfDay().set(instant, millisOfDay);
}
/**
* Returns a datetime millisecond instant, formed from the given year,
* month, day, hour, minute, second, and millisecond values. The set of
* given values must refer to a valid datetime, or else an
* IllegalArgumentException is thrown.
* <p>
* The default implementation calls upon separate DateTimeFields to
* determine the result. Subclasses are encouraged to provide a more
* efficient implementation.
*
* @param year year to use
* @param monthOfYear month to use
* @param dayOfMonth day of month to use
* @param hourOfDay hour to use
* @param minuteOfHour minute to use
* @param secondOfMinute second to use
* @param millisOfSecond millisecond to use
* @return millisecond instant from 1970-01-01T00:00:00Z
*/
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
long instant = year().set(0, year);
instant = monthOfYear().set(instant, monthOfYear);
instant = dayOfMonth().set(instant, dayOfMonth);
instant = hourOfDay().set(instant, hourOfDay);
instant = minuteOfHour().set(instant, minuteOfHour);
instant = secondOfMinute().set(instant, secondOfMinute);
return millisOfSecond().set(instant, millisOfSecond);
}
/**
* Returns a datetime millisecond instant, from from the given instant,
* hour, minute, second, and millisecond values. The set of given values
* must refer to a valid datetime, or else an IllegalArgumentException is
* thrown.
* <p>
*
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> /**
* Gets the values of a partial from an instant.
*
* @param partial the partial instant to use
* @param instant the instant to query
* @return the values of the partial extracted from the instant
*/
public int[] get(ReadablePartial partial, long instant) {
int size = partial.size();
int[] values = new int[size];
for (int i = 0; i < size; i++) {
values[i] = partial.getFieldType(i).getField(this).get(instant);
}
return values;
}
/**
* Sets the partial into the instant.
*
* @param partial the partial instant to use
* @param instant the instant to update
* @return the updated instant
*/
public long set(ReadablePartial partial, long instant) {
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(this).set(instant, partial.getValue(i));
}
return instant;
}
//-----------------------------------------------------------------------
/**
* Gets the values of a period from an interval.
*
* @param period the period instant to use
* @param startInstant the start instant of an interval to query
* @param endInstant the start instant of an interval to query
* @return the values of the period extracted from the interval
*/
public int[] get(ReadablePeriod period, long startInstant, long endInstant) {
int size = period.size();
int[] values = new int[size];
if (startInstant != endInstant) {
for (int i = 0; i < size; i++) {
DurationField field = period.getFieldType(i).getField(this);
int value = field.getDifference(endInstant, startInstant);
startInstant = field.add(startInstant, value);
values[i] = value;
}
}
return values;
}
/**
* Gets the values of a period from an interval.
*
* @param period the period instant to use
* @param duration the duration to query
* @return the values of the period extracted from the duration
*/
public int[] get(ReadablePeriod period, long duration) {
int size = period.size();
int[] values = new int[size];
if (duration != 0) {
long current = 0;
for (int i = 0; i < size; i++) {
DurationField field = period.getFieldType(i).getField(this);
if (field.isPrecise()) {
int value = field.getDifference(duration, current);
current = field.add(current, value);
values[i] = value;
}
}
}
return values;
}
/**
* Adds the period to the instant, specifying the number of times to add.
*
* @param period the period
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> to add, null means add nothing
* @param instant the instant to add to
* @param scalar the number of times to add
* @return the updated instant
*/
public long add(ReadablePeriod period, long instant, int scalar) {
if (scalar != 0 && period != null) {
for (int i = 0, isize = period.size(); i < isize; i++) {
long value = period.getValue(i); // use long to allow for multiplication (fits OK)
if (value != 0) {
instant = period.getFieldType(i).getField(this).add(instant, value * scalar);
}
}
}
return instant;
}
//-----------------------------------------------------------------------
/**
* Adds the duration to the instant, specifying the number of times to add.
*
* @param instant the instant to add to
* @param duration the duration to add
* @param scalar the number of times to add
* @return the updated instant
*/
public long add(long instant, long duration, int scalar) {
if (duration == 0 || scalar == 0) {
return instant;
}
long add = FieldUtils.safeMultiply(duration, scalar);
return FieldUtils.safeAdd(instant, add);
}
// Millis
//-----------------------------------------------------------------------
/**
* Get the millis duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField millis() {
return UnsupportedDurationField.getInstance(DurationFieldType.millis());
}
/**
* Get the millis of second field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField millisOfSecond() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.millisOfSecond(), millis());
}
/**
* Get the millis of day field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField millisOfDay() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.millisOfDay(), millis());
}
// Second
//-----------------------------------------------------------------------
/**
* Get the seconds duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField seconds() {
return UnsupportedDurationField.getInstance(DurationFieldType.seconds());
}
/**
* Get the second of minute field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField secondOfMinute() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.secondOfMinute(), seconds());
}
/**
* Get the second of day field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField secondOfDay() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.secondOfDay(), seconds());
}
// Minute
//-----------------------------------------------------------------------
/**
* Get the minutes duration field for this chronology.
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> *
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField minutes() {
return UnsupportedDurationField.getInstance(DurationFieldType.minutes());
}
/**
* Get the minute of hour field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField minuteOfHour() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.minuteOfHour(), minutes());
}
/**
* Get the minute of day field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField minuteOfDay() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.minuteOfDay(), minutes());
}
// Hour
//-----------------------------------------------------------------------
/**
* Get the hours duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField hours() {
return UnsupportedDurationField.getInstance(DurationFieldType.hours());
}
/**
* Get the hour of day (0-23) field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField hourOfDay() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.hourOfDay(), hours());
}
/**
* Get the hour of day (offset to 1-24) field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField clockhourOfDay() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.clockhourOfDay(), hours());
}
// Halfday
//-----------------------------------------------------------------------
/**
* Get the halfdays duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField halfdays() {
return UnsupportedDurationField.getInstance(DurationFieldType.halfdays());
}
/**
* Get the hour of am/pm (0-11) field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField hourOfHalfday() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.hourOfHalfday(), hours());
}
/**
* Get the hour of am/pm (offset to 1-12) field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField clockhourOfHalfday() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.clockhourOfHalfday(), hours());
}
/**
* Get the AM(0) PM(1) field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField halfdayOfDay() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.halfdayOfDay(), halfdays());
}
// Day
//-----------------------------------------------------------------------
/**
* Get the days duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
public DurationField days() {
return UnsupportedDurationField.getInstance(DurationFieldType.days());
}
/**
* Get the day of week field for this chronology.
*
* <p>DayOfWeek values are defined in
* {@link org.joda.time.DateTimeConstants DateTimeConstants}.
* They use the ISO definitions, where 1 is Monday and 7 is Sunday.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField dayOfWeek() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.dayOfWeek(), days());
}
/**
* Get the day of month field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField dayOfMonth() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.dayOfMonth(), days());
}
/**
* Get the day of year field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField dayOfYear() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.dayOfYear(), days());
}
// Week
//-----------------------------------------------------------------------
/**
* Get the weeks duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField weeks() {
return UnsupportedDurationField.getInstance(DurationFieldType.weeks());
}
/**
* Get the week of a week based year field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField weekOfWeekyear() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.weekOfWeekyear(), weeks());
}
// Weekyear
//-----------------------------------------------------------------------
/**
* Get the weekyears duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField weekyears() {
return UnsupportedDurationField.getInstance(DurationFieldType.weekyears());
}
/**
* Get the year of a week based year field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField weekyear() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.weekyear(), weekyears());
}
/**
* Get the year of a week based year in a century field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField weekyearOfCentury() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.weekyearOfCentury(), weekyears());
}
// Month
//-----------------------------------------------------------------------
/**
* Get the months duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField months() {
return UnsupportedDurationField.getInstance(DurationFieldType.months());
}
/**
* Get the month of year field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField monthOfYear() {
return UnsupportedDateTimeField.getInstance
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(DateTimeFieldType.monthOfYear(), months());
}
// Year
//-----------------------------------------------------------------------
/**
* Get the years duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField years() {
return UnsupportedDurationField.getInstance(DurationFieldType.years());
}
/**
* Get the year field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField year() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.year(), years());
}
/**
* Get the year of era field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField yearOfEra() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.yearOfEra(), years());
}
/**
* Get the year of century field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField yearOfCentury() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.yearOfCentury(), years());
}
// Century
//-----------------------------------------------------------------------
/**
* Get the centuries duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField centuries() {
return UnsupportedDurationField.getInstance(DurationFieldType.centuries());
}
/**
* Get the century of era field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField centuryOfEra() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.centuryOfEra(), centuries());
}
// Era
//-----------------------------------------------------------------------
/**
* Get the eras duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public DurationField eras() {
return UnsupportedDurationField.getInstance(DurationFieldType.eras());
}
/**
* Get the era field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public DateTimeField era() {
return UnsupportedDateTimeField.getInstance(DateTimeFieldType.era(), eras());
}
//-----------------------------------------------------------------------
/**
* Gets a debugging toString.
*
* @return a debugging string
*/
public abstract String toString();
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> boolean isPrecise() {
return true;
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public int getValue(long duration) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long getValueAsLong(long duration) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public int getValue(long duration, long instant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long getValueAsLong(long duration, long instant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long getMillis(int value) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long getMillis(long value) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long getMillis(int value, long instant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long getMillis(long value, long instant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long add(long instant, int value) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long add(long instant, long value) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public int getDifference(long minuendInstant, long subtrahendInstant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
throw unsupported();
}
/**
* Always returns zero.
*
* @return zero always
*/
public long getUnitMillis() {
return 0;
}
/**
* Always returns zero, indicating that sort order is not relevent.
*
* @return zero always
*/
public int compareTo(DurationField durationField) {
return 0;
}
//------------------------------------------------------------------------
/**
* Compares this duration field to another.
*
* @param obj the object to compare to
* @return true if equal
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof UnsupportedDurationField) {
UnsupportedDurationField other = (UnsupportedDurationField) obj;
if (other.getName() == null) {
return (getName() == null);
}
return (other.getName().equals(getName()));
}
return false;
}
/**
* Gets a suitable hashcode.
*
* @return the
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> null, false);
}
/**
* ZoneInfoProvider searches the given ClassLoader resource path for
* compiled data files.
*
* @param loader ClassLoader to load compiled data files from. If null,
* use system ClassLoader.
* @throws IOException if directory or map file cannot be read
*/
public ZoneInfoProvider(String resourcePath, ClassLoader loader)
throws IOException
{
this(resourcePath, loader, true);
}
/**
* @param favorSystemLoader when true, use the system class loader if
* loader null. When false, use the current class loader if loader is null.
*/
private ZoneInfoProvider(String resourcePath,
ClassLoader loader, boolean favorSystemLoader)
throws IOException
{
if (resourcePath == null) {
throw new IllegalArgumentException("No resource path provided");
}
if (!resourcePath.endsWith("/")) {
resourcePath += '/';
}
iFileDir = null;
iResourcePath = resourcePath;
if (loader == null && !favorSystemLoader) {
loader = getClass().getClassLoader();
}
iLoader = loader;
iZoneInfoMap = loadZoneInfoMap(openResource("ZoneInfoMap"));
}
//-----------------------------------------------------------------------
/**
* If an error is thrown while loading zone data, uncaughtException is
* called to log the error and null is returned for this and all future
* requests.
*
* @param id the id to load
* @return the loaded zone
*/
public DateTimeZone getZone(String id) {
if (id == null) {
return null;
}
Object obj = iZoneInfoMap.get(id);
if (obj == null) {
return null;
}
if (id.equals(obj)) {
// Load zone data for the first time.
return loadZoneData(id);
}
if (obj instanceof SoftReference<?>) {
@SuppressWarnings("unchecked")
SoftReference<DateTimeZone> ref = (SoftReference<DateTimeZone>) obj;
DateTimeZone tz = ref.get();
if (tz != null) {
return tz;
}
// Reference cleared; load data again.
return loadZoneData(id);
}
// If this point is reached, mapping must link to another.
return getZone((String)obj);
}
/**
* Gets a list of all the available zone ids.
*
* @return the zone ids
*/
public Set<String> getAvailableIDs() {
// Return a copy of the keys rather than an umodifiable collection.
// This prevents ConcurrentModificationExceptions from being thrown by
// some JVMs if zones are opened while this set is iterated over.
return new TreeSet<String>(iZoneInfoMap.keySet());
}
/**
* Called if an exception is thrown from getZone while loading zone data.
*
* @param ex the exception
*/
protected void uncaughtException(Exception ex) {
Thread t = Thread.currentThread();
t.get
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> }
private final DateTimeFieldType iDateTimeFieldType;
private final DurationFieldType iDurationFieldType;
private final String iFieldName;
private final Number iNumberValue;
private final String iStringValue;
private final Number iLowerBound;
private final Number iUpperBound;
private String iMessage;
/**
* Constructor.
*
* @param fieldType type of field being set
* @param value illegal value being set
* @param lowerBound lower legal field value, or null if not applicable
* @param upperBound upper legal field value, or null if not applicable
*/
public IllegalFieldValueException(DateTimeFieldType fieldType,
Number value, Number lowerBound, Number upperBound) {
super(createMessage(fieldType.getName(), value, lowerBound, upperBound, null));
iDateTimeFieldType = fieldType;
iDurationFieldType = null;
iFieldName = fieldType.getName();
iNumberValue = value;
iStringValue = null;
iLowerBound = lowerBound;
iUpperBound = upperBound;
iMessage = super.getMessage();
}
/**
* Constructor.
*
* @param fieldType type of field being set
* @param value illegal value being set
* @param explain an explanation
* @since 1.5
*/
public IllegalFieldValueException(DateTimeFieldType fieldType,
Number value, String explain) {
super(createMessage(fieldType.getName(), value, null, null, explain));
iDateTimeFieldType = fieldType;
iDurationFieldType = null;
iFieldName = fieldType.getName();
iNumberValue = value;
iStringValue = null;
iLowerBound = null;
iUpperBound = null;
iMessage = super.getMessage();
}
/**
* Constructor.
*
* @param fieldType type of field being set
* @param value illegal value being set
* @param lowerBound lower legal field value, or null if not applicable
* @param upperBound upper legal field value, or null if not applicable
*/
public IllegalFieldValueException(DurationFieldType fieldType,
Number value, Number lowerBound, Number upperBound) {
super(createMessage(fieldType.getName(), value, lowerBound, upperBound, null));
iDateTimeFieldType = null;
iDurationFieldType = fieldType;
iFieldName = fieldType.getName();
iNumberValue = value;
iStringValue = null;
iLowerBound = lowerBound;
iUpperBound = upperBound;
iMessage = super.getMessage();
}
/**
* Constructor.
*
* @param fieldName name of field being set
* @param value illegal value being set
* @param lowerBound lower legal field value, or null if not applicable
* @param upperBound upper legal field value, or null if not applicable
*/
public IllegalFieldValueException(String fieldName,
Number value, Number lowerBound, Number upperBound) {
super(createMessage(fieldName, value, lowerBound, upperBound, null));
iDateTimeFieldType = null;
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
iDurationFieldType = null;
iFieldName = fieldName;
iNumberValue = value;
iStringValue = null;
iLowerBound = lowerBound;
iUpperBound = upperBound;
iMessage = super.getMessage();
}
/**
* Constructor.
*
* @param fieldType type of field being set
* @param value illegal value being set
*/
public IllegalFieldValueException(DateTimeFieldType fieldType, String value) {
super(createMessage(fieldType.getName(), value));
iDateTimeFieldType = fieldType;
iDurationFieldType = null;
iFieldName = fieldType.getName();
iStringValue = value;
iNumberValue = null;
iLowerBound = null;
iUpperBound = null;
iMessage = super.getMessage();
}
/**
* Constructor.
*
* @param fieldType type of field being set
* @param value illegal value being set
*/
public IllegalFieldValueException(DurationFieldType fieldType, String value) {
super(createMessage(fieldType.getName(), value));
iDateTimeFieldType = null;
iDurationFieldType = fieldType;
iFieldName = fieldType.getName();
iStringValue = value;
iNumberValue = null;
iLowerBound = null;
iUpperBound = null;
iMessage = super.getMessage();
}
/**
* Constructor.
*
* @param fieldName name of field being set
* @param value illegal value being set
*/
public IllegalFieldValueException(String fieldName, String value) {
super(createMessage(fieldName, value));
iDateTimeFieldType = null;
iDurationFieldType = null;
iFieldName = fieldName;
iStringValue = value;
iNumberValue = null;
iLowerBound = null;
iUpperBound = null;
iMessage = super.getMessage();
}
//-----------------------------------------------------------------------
/**
* Returns the DateTimeFieldType whose value was invalid, or null if not applicable.
*
* @return the datetime field type
*/
public DateTimeFieldType getDateTimeFieldType() {
return iDateTimeFieldType;
}
/**
* Returns the DurationFieldType whose value was invalid, or null if not applicable.
*
* @return the duration field type
*/
public DurationFieldType getDurationFieldType() {
return iDurationFieldType;
}
/**
* Returns the name of the field whose value was invalid.
*
* @return the field name
*/
public String getFieldName() {
return iFieldName;
}
/**
* Returns the illegal integer value assigned to the field, or null if not applicable.
*
* @return the value
*/
public Number getIllegalNumberValue() {
return iNumberValue;
}
/**
* Returns the illegal string value assigned to the field, or null if not applicable.
*
* @return the value
*/
public String getIllegalStringValue() {
return iStringValue;
}
/**
* Returns the illegal value assigned to the field as a non-null string.
*
* @return the value
*/
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
/**
* Generic offset adjusting datetime field.
* <p>
* OffsetDateTimeField is thread-safe and immutable.
*
* @author Brian S O'Neill
* @since 1.0
*/
public class OffsetDateTimeField extends DecoratedDateTimeField {
private static final long serialVersionUID = 3145790132623583142L;
private final int iOffset;
private final int iMin;
private final int iMax;
/**
* Constructor.
*
* @param field the field to wrap, like "year()".
* @param offset offset to add to field values
* @throws IllegalArgumentException if offset is zero
*/
public OffsetDateTimeField(DateTimeField field, int offset) {
this(field, (field == null ? null : field.getType()), offset, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
/**
* Constructor.
*
* @param field the field to wrap, like "year()".
* @param type the field type this field actually uses
* @param offset offset to add to field values
* @throws IllegalArgumentException if offset is zero
*/
public OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset) {
this(field, type, offset, Integer.MIN_VALUE, Integer.MAX_VALUE);
}
/**
* Constructor.
*
* @param field the field to wrap, like "year()".
* @param type the field type this field actually uses
* @param offset offset to add to field values
* @param minValue minimum allowed value
* @param maxValue maximum allowed value
* @throws IllegalArgumentException if offset is zero
*/
public OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset,
int minValue, int maxValue) {
super(field, type);
if (offset == 0) {
throw new IllegalArgumentException("The offset cannot be zero");
}
iOffset = offset;
if (minValue < (field.getMinimumValue
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
import org.joda.time.field.PreciseDurationDateTimeField;
/**
* Provides time calculations for the day of the month component of time.
*
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.1, refactored from GJDayOfMonthDateTimeField
*/
final class BasicDayOfMonthDateTimeField extends PreciseDurationDateTimeField {
private static final long serialVersionUID = -4677223814028011723L;
private final BasicChronology iChronology;
/**
* Restricted constructor.
*/
BasicDayOfMonthDateTimeField(BasicChronology chronology, DurationField days) {
super(DateTimeFieldType.dayOfMonth(), days);
iChronology = chronology;
}
//-----------------------------------------------------------------------
public int get(long instant) {
return iChronology.getDayOfMonth(instant);
}
public DurationField getRangeDurationField() {
return iChronology.months();
}
public int getMinimumValue() {
return 1;
}
public int getMaximumValue() {
return iChronology.getDaysInMonthMax();
}
public int getMaximumValue(long instant) {
return iChronology.getDaysInMonthMax(instant);
}
public int getMaximumValue(ReadablePartial partial) {
if (partial.isSupported(DateTimeFieldType.monthOfYear())) {
int month = partial.get(DateTimeFieldType.monthOfYear());
if (partial.isSupported(DateTimeFieldType.year())) {
int year = partial.get(DateTimeFieldType.year());
return iChronology.getDaysInYearMonth(year, month);
}
return iChronology.getDaysInMonthMax(month);
}
return getMaximumValue();
}
public int getMaximumValue(ReadablePartial partial, int[] values) {
int size = partial.size();
for (int i = 0; i <
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> size; i++) {
if (partial.getFieldType(i) == DateTimeFieldType.monthOfYear()) {
int month = values[i];
for (int j = 0; j < size; j++) {
if (partial.getFieldType(j) == DateTimeFieldType.year()) {
int year = values[j];
return iChronology.getDaysInYearMonth(year, month);
}
}
return iChronology.getDaysInMonthMax(month);
}
}
return getMaximumValue();
}
protected int getMaximumValueForSet(long instant, int value) {
return iChronology.getDaysInMonthMaxForSet(instant, value);
}
/**
* Serialization singleton
*/
private Object readResolve() {
return iChronology.dayOfMonth();
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>Field iYearOfEra;
private transient DateTimeField iYearOfCentury;
private transient DateTimeField iCenturyOfEra;
private transient DateTimeField iEra;
// Bit set determines which base fields are used
// bit 1 set: hourOfDay, minuteOfHour, secondOfMinute, and millisOfSecond fields
// bit 2 set: millisOfDayField
// bit 3 set: year, monthOfYear, and dayOfMonth fields
private transient int iBaseFlags;
/**
* Constructor calls the assemble method, enabling subclasses to define its
* supported fields. If a base chronology is supplied, the field set
* initially contains references to each base chronology field.
* <p>
* Other methods in this class will delegate to the base chronology, if it
* can be determined that the base chronology will produce the same results
* as AbstractChronology.
*
* @param base optional base chronology to copy initial fields from
* @param param optional param object avalable for assemble method
*/
protected AssembledChronology(Chronology base, Object param) {
iBase = base;
iParam = param;
setFields();
}
public DateTimeZone getZone() {
Chronology base;
if ((base = iBase) != null) {
return base.getZone();
}
return null;
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int millisOfDay)
throws IllegalArgumentException
{
Chronology base;
if ((base = iBase) != null && (iBaseFlags & 6) == 6) {
// Only call specialized implementation if applicable fields are the same.
return base.getDateTimeMillis(year, monthOfYear, dayOfMonth, millisOfDay);
}
return super.getDateTimeMillis(year, monthOfYear, dayOfMonth, millisOfDay);
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
Chronology base;
if ((base = iBase) != null && (iBaseFlags & 5) == 5) {
// Only call specialized implementation if applicable fields are the same.
return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
return super.getDateTimeMillis(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
public long getDateTimeMillis(long instant,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
Chronology base;
if ((base = iBase) != null && (iBaseFlags & 1) == 1) {
// Only call specialized implementation if applicable fields are the same.
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> return base.getDateTimeMillis
(instant, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
return super.getDateTimeMillis
(instant, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
public final DurationField millis() {
return iMillis;
}
public final DateTimeField millisOfSecond() {
return iMillisOfSecond;
}
public final DateTimeField millisOfDay() {
return iMillisOfDay;
}
public final DurationField seconds() {
return iSeconds;
}
public final DateTimeField secondOfMinute() {
return iSecondOfMinute;
}
public final DateTimeField secondOfDay() {
return iSecondOfDay;
}
public final DurationField minutes() {
return iMinutes;
}
public final DateTimeField minuteOfHour() {
return iMinuteOfHour;
}
public final DateTimeField minuteOfDay() {
return iMinuteOfDay;
}
public final DurationField hours() {
return iHours;
}
public final DateTimeField hourOfDay() {
return iHourOfDay;
}
public final DateTimeField clockhourOfDay() {
return iClockhourOfDay;
}
public final DurationField halfdays() {
return iHalfdays;
}
public final DateTimeField hourOfHalfday() {
return iHourOfHalfday;
}
public final DateTimeField clockhourOfHalfday() {
return iClockhourOfHalfday;
}
public final DateTimeField halfdayOfDay() {
return iHalfdayOfDay;
}
public final DurationField days() {
return iDays;
}
public final DateTimeField dayOfWeek() {
return iDayOfWeek;
}
public final DateTimeField dayOfMonth() {
return iDayOfMonth;
}
public final DateTimeField dayOfYear() {
return iDayOfYear;
}
public final DurationField weeks() {
return iWeeks;
}
public final DateTimeField weekOfWeekyear() {
return iWeekOfWeekyear;
}
public final DurationField weekyears() {
return iWeekyears;
}
public final DateTimeField weekyear() {
return iWeekyear;
}
public final DateTimeField weekyearOfCentury() {
return iWeekyearOfCentury;
}
public final DurationField months() {
return iMonths;
}
public final DateTimeField monthOfYear() {
return iMonthOfYear;
}
public final DurationField years() {
return iYears;
}
public final DateTimeField year() {
return iYear;
}
public final DateTimeField yearOfEra() {
return iYearOfEra;
}
public final DateTimeField yearOfCentury() {
return iYearOfCentury;
}
public final DurationField centuries() {
return iCenturies;
}
public final DateTimeField centuryOfEra() {
return iCenturyOfEra;
}
public final DurationField
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> = fields.hourOfDay) != null ? f : super.hourOfDay();
iClockhourOfDay = (f = fields.clockhourOfDay) != null ? f : super.clockhourOfDay();
iHourOfHalfday = (f = fields.hourOfHalfday) != null ? f : super.hourOfHalfday();
iClockhourOfHalfday = (f = fields.clockhourOfHalfday) != null ? f : super.clockhourOfHalfday();
iHalfdayOfDay = (f = fields.halfdayOfDay) != null ? f : super.halfdayOfDay();
iDayOfWeek = (f = fields.dayOfWeek) != null ? f : super.dayOfWeek();
iDayOfMonth = (f = fields.dayOfMonth) != null ? f : super.dayOfMonth();
iDayOfYear = (f = fields.dayOfYear) != null ? f : super.dayOfYear();
iWeekOfWeekyear = (f = fields.weekOfWeekyear) != null ? f : super.weekOfWeekyear();
iWeekyear = (f = fields.weekyear) != null ? f : super.weekyear();
iWeekyearOfCentury = (f = fields.weekyearOfCentury) != null ? f : super.weekyearOfCentury();
iMonthOfYear = (f = fields.monthOfYear) != null ? f : super.monthOfYear();
iYear = (f = fields.year) != null ? f : super.year();
iYearOfEra = (f = fields.yearOfEra) != null ? f : super.yearOfEra();
iYearOfCentury = (f = fields.yearOfCentury) != null ? f : super.yearOfCentury();
iCenturyOfEra = (f = fields.centuryOfEra) != null ? f : super.centuryOfEra();
iEra = (f = fields.era) != null ? f : super.era();
}
int flags;
if (iBase == null) {
flags = 0;
} else {
flags =
((iHourOfDay == iBase.hourOfDay() &&
iMinuteOfHour == iBase.minuteOfHour() &&
iSecondOfMinute == iBase.secondOfMinute() &&
iMillisOfSecond == iBase.millisOfSecond() ) ? 1 : 0) |
((iMillisOfDay == iBase.millisOfDay()) ? 2 : 0) |
((iYear == iBase.year() &&
iMonthOfYear == iBase.monthOfYear() &&
iDayOfMonth == iBase.dayOfMonth() ) ? 4 : 0);
}
iBaseFlags = flags;
}
private void readObject(ObjectInputStream in)
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> throws IOException, ClassNotFoundException {
in.defaultReadObject();
setFields();
}
/**
* A container of fields used for assembling a chronology.
*/
public static final class Fields {
public DurationField millis;
public DurationField seconds;
public DurationField minutes;
public DurationField hours;
public DurationField halfdays;
public DurationField days;
public DurationField weeks;
public DurationField weekyears;
public DurationField months;
public DurationField years;
public DurationField centuries;
public DurationField eras;
public DateTimeField millisOfSecond;
public DateTimeField millisOfDay;
public DateTimeField secondOfMinute;
public DateTimeField secondOfDay;
public DateTimeField minuteOfHour;
public DateTimeField minuteOfDay;
public DateTimeField hourOfDay;
public DateTimeField clockhourOfDay;
public DateTimeField hourOfHalfday;
public DateTimeField clockhourOfHalfday;
public DateTimeField halfdayOfDay;
public DateTimeField dayOfWeek;
public DateTimeField dayOfMonth;
public DateTimeField dayOfYear;
public DateTimeField weekOfWeekyear;
public DateTimeField weekyear;
public DateTimeField weekyearOfCentury;
public DateTimeField monthOfYear;
public DateTimeField year;
public DateTimeField yearOfEra;
public DateTimeField yearOfCentury;
public DateTimeField centuryOfEra;
public DateTimeField era;
Fields() {
}
/**
* Copy the supported fields from a chronology into this container.
*/
public void copyFieldsFrom(Chronology chrono) {
{
DurationField f;
if (isSupported(f = chrono.millis())) {
millis = f;
}
if (isSupported(f = chrono.seconds())) {
seconds = f;
}
if (isSupported(f = chrono.minutes())) {
minutes = f;
}
if (isSupported(f = chrono.hours())) {
hours = f;
}
if (isSupported(f = chrono.halfdays())) {
halfdays = f;
}
if (isSupported(f = chrono.days())) {
days = f;
}
if (isSupported(f = chrono.weeks())) {
weeks = f;
}
if (isSupported(f = chrono.weekyears())) {
weekyears = f;
}
if (isSupported(f = chrono.months())) {
months = f;
}
if (isSupported(f = chrono.years())) {
years = f;
}
if (isSupported(f = chrono.centuries())) {
centuries = f;
}
if (isSupported(f = chrono.eras())) {
eras = f;
}
}
{
DateTimeField f;
if (isSupported(f = chrono.millisOfSecond())) {
millisOfSecond = f;
}
if (isSupported(f = chrono.millisOfDay())) {
millisOfDay = f
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>;
}
if (isSupported(f = chrono.secondOfMinute())) {
secondOfMinute = f;
}
if (isSupported(f = chrono.secondOfDay())) {
secondOfDay = f;
}
if (isSupported(f = chrono.minuteOfHour())) {
minuteOfHour = f;
}
if (isSupported(f = chrono.minuteOfDay())) {
minuteOfDay = f;
}
if (isSupported(f = chrono.hourOfDay())) {
hourOfDay = f;
}
if (isSupported(f = chrono.clockhourOfDay())) {
clockhourOfDay = f;
}
if (isSupported(f = chrono.hourOfHalfday())) {
hourOfHalfday = f;
}
if (isSupported(f = chrono.clockhourOfHalfday())) {
clockhourOfHalfday = f;
}
if (isSupported(f = chrono.halfdayOfDay())) {
halfdayOfDay = f;
}
if (isSupported(f = chrono.dayOfWeek())) {
dayOfWeek = f;
}
if (isSupported(f = chrono.dayOfMonth())) {
dayOfMonth = f;
}
if (isSupported(f = chrono.dayOfYear())) {
dayOfYear = f;
}
if (isSupported(f = chrono.weekOfWeekyear())) {
weekOfWeekyear = f;
}
if (isSupported(f = chrono.weekyear())) {
weekyear = f;
}
if (isSupported(f = chrono.weekyearOfCentury())) {
weekyearOfCentury = f;
}
if (isSupported(f = chrono.monthOfYear())) {
monthOfYear = f;
}
if (isSupported(f = chrono.year())) {
year = f;
}
if (isSupported(f = chrono.yearOfEra())) {
yearOfEra = f;
}
if (isSupported(f = chrono.yearOfCentury())) {
yearOfCentury = f;
}
if (isSupported(f = chrono.centuryOfEra())) {
centuryOfEra = f;
}
if (isSupported(f = chrono.era())) {
era = f;
}
}
}
private static boolean isSupported(DurationField field) {
return field == null ? false : field.isSupported();
}
private static boolean isSupported(DateTimeField field) {
return field == null ? false : field.isSupported();
}
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> @return the new total
* @throws ArithmeticException if the value is too big or too small
*/
public static long safeMultiply(long val1, long val2) {
if (val2 == 1) {
return val1;
}
if (val1 == 1) {
return val2;
}
if (val1 == 0 || val2 == 0) {
return 0;
}
long total = val1 * val2;
if (total / val2 != val1 || val1 == Long.MIN_VALUE && val2 == -1 || val2 == Long.MIN_VALUE && val1 == -1) {
throw new ArithmeticException("Multiplication overflows a long: " + val1 + " * " + val2);
}
return total;
}
/**
* Casts to an int throwing an exception if overflow occurs.
*
* @param value the value
* @return the value as an int
* @throws ArithmeticException if the value is too big or too small
*/
public static int safeToInt(long value) {
if (Integer.MIN_VALUE <= value && value <= Integer.MAX_VALUE) {
return (int) value;
}
throw new ArithmeticException("Value cannot fit in an int: " + value);
}
/**
* Multiply two values to return an int throwing an exception if overflow occurs.
*
* @param val1 the first value
* @param val2 the second value
* @return the new total
* @throws ArithmeticException if the value is too big or too small
*/
public static int safeMultiplyToInt(long val1, long val2) {
long val = FieldUtils.safeMultiply(val1, val2);
return FieldUtils.safeToInt(val);
}
//-----------------------------------------------------------------------
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
*/
public static void verifyValueBounds(DateTimeField field,
int value, int lowerBound, int upperBound) {
if ((value < lowerBound) || (value > upperBound)) {
throw new IllegalFieldValueException
(field.getType(), Integer.valueOf(value),
Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
}
}
/**
* Verify that input values are within specified bounds.
*
* @param value the value to check
* @param lowerBound the lower bound allowed for value
* @param upperBound the upper bound allowed for value
* @throws IllegalFieldValueException if value is not in the specified bounds
* @since 1.1
*/
public static void verifyValueBounds(DateTimeFieldType fieldType,
int value, int lowerBound, int upperBound) {
if ((value
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
* @return true if equal
* @since 1.4
*/
public static boolean equals(Object object1, Object object2) {
if (object1 == object2) {
return true;
}
if (object1 == null || object2 == null) {
return false;
}
return object1.equals(object2);
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>.joda.time.chrono.JulianChronology
* @see org.joda.time.chrono.CopticChronology
* @see org.joda.time.chrono.BuddhistChronology
* @see org.joda.time.chrono.EthiopicChronology
*
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.0
*/
public abstract class Chronology {
/**
* Returns the DateTimeZone that this Chronology operates in, or null if
* unspecified.
*
* @return the DateTimeZone, null if unspecified
*/
public abstract DateTimeZone getZone();
/**
* Returns an instance of this Chronology that operates in the UTC time
* zone. Chronologies that do not operate in a time zone or are already
* UTC must return themself.
*
* @return a version of this chronology that ignores time zones
*/
public abstract Chronology withUTC();
/**
* Returns an instance of this Chronology that operates in any time zone.
*
* @return a version of this chronology with a specific time zone
* @param zone to use, or default if null
* @see org.joda.time.chrono.ZonedChronology
*/
public abstract Chronology withZone(DateTimeZone zone);
/**
* Returns a datetime millisecond instant, formed from the given year,
* month, day, and millisecond values. The set of given values must refer
* to a valid datetime, or else an IllegalArgumentException is thrown.
* <p>
* The default implementation calls upon separate DateTimeFields to
* determine the result. Subclasses are encouraged to provide a more
* efficient implementation.
*
* @param year year to use
* @param monthOfYear month to use
* @param dayOfMonth day of month to use
* @param millisOfDay millisecond to use
* @return millisecond instant from 1970-01-01T00:00:00Z
* @throws IllegalArgumentException if the values are invalid
*/
public abstract long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth, int millisOfDay);
/**
* Returns a datetime millisecond instant, formed from the given year,
* month, day, hour, minute, second, and millisecond values. The set of
* given values must refer to a valid datetime, or else an
* IllegalArgumentException is thrown.
* <p>
* The default implementation calls upon separate DateTimeFields to
* determine the result. Subclasses are encouraged to provide a more
* efficient implementation.
*
* @param year year to use
* @param monthOfYear month to use
* @param dayOfMonth day of month to use
* @param hourOfDay hour to use
* @param minuteOfHour minute to use
* @param secondOfMinute second to use
* @param millis
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>OfSecond millisecond to use
* @return millisecond instant from 1970-01-01T00:00:00Z
* @throws IllegalArgumentException if the values are invalid
*/
public abstract long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond);
/**
* Returns a datetime millisecond instant, from from the given instant,
* hour, minute, second, and millisecond values. The set of given values
* must refer to a valid datetime, or else an IllegalArgumentException is
* thrown.
* <p>
* The default implementation calls upon separate DateTimeFields to
* determine the result. Subclasses are encouraged to provide a more
* efficient implementation.
*
* @param instant instant to start from
* @param hourOfDay hour to use
* @param minuteOfHour minute to use
* @param secondOfMinute second to use
* @param millisOfSecond millisecond to use
* @return millisecond instant from 1970-01-01T00:00:00Z
* @throws IllegalArgumentException if the values are invalid
*/
public abstract long getDateTimeMillis(long instant,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond);
//-----------------------------------------------------------------------
/**
* Validates whether the values are valid for the fields of a partial instant.
*
* @param partial the partial instant to validate
* @param values the values to validate, not null, match fields in partial
* @throws IllegalArgumentException if the instant is invalid
*/
public abstract void validate(ReadablePartial partial, int[] values);
/**
* Gets the values of a partial from an instant.
*
* @param partial the partial instant to use
* @param instant the instant to query
* @return the values of this partial extracted from the instant
*/
public abstract int[] get(ReadablePartial partial, long instant);
/**
* Sets the partial into the instant.
*
* @param partial the partial instant to use
* @param instant the instant to update
* @return the updated instant
*/
public abstract long set(ReadablePartial partial, long instant);
//-----------------------------------------------------------------------
/**
* Gets the values of a period from an interval.
*
* @param period the period instant to use
* @param startInstant the start instant of an interval to query
* @param endInstant the start instant of an interval to query
* @return the values of the period extracted from the interval
*/
public abstract int[] get(ReadablePeriod period, long startInstant, long endInstant);
/**
* Gets the values of a period from an interval.
*
* @param period the period instant to use
* @param duration the duration to query
* @return the values of the period extracted from the duration
*/
public abstract int[] get(Readable
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
/**
* Get the months duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public abstract DurationField months();
/**
* Get the month of year field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public abstract DateTimeField monthOfYear();
// Year
//-----------------------------------------------------------------------
/**
* Get the years duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public abstract DurationField years();
/**
* Get the year field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public abstract DateTimeField year();
/**
* Get the year of era field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public abstract DateTimeField yearOfEra();
/**
* Get the year of century field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public abstract DateTimeField yearOfCentury();
// Century
//-----------------------------------------------------------------------
/**
* Get the centuries duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public abstract DurationField centuries();
/**
* Get the century of era field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public abstract DateTimeField centuryOfEra();
// Era
//-----------------------------------------------------------------------
/**
* Get the eras duration field for this chronology.
*
* @return DurationField or UnsupportedDurationField if unsupported
*/
public abstract DurationField eras();
/**
* Get the era field for this chronology.
*
* @return DateTimeField or UnsupportedDateTimeField if unsupported
*/
public abstract DateTimeField era();
//-----------------------------------------------------------------------
/**
* Gets a debugging toString.
*
* @return a debugging string
*/
public abstract String toString();
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>>
* <li>add/subtract - <code>monthOfYear().addToCopy()</code>
* <li>set - <code>monthOfYear().setCopy()</code>
* </ul>
* <p>
* MonthDay is thread-safe and immutable, provided that the Chronology is as well.
* All standard Chronology classes supplied are thread-safe and immutable.
*
* @author Chris Pheby
* @since 2.0
*/
public final class MonthDay
extends BasePartial
implements ReadablePartial, Serializable {
/** Serialization version */
private static final long serialVersionUID = 2954560699050434609L;
/** The singleton set of field types */
private static final DateTimeFieldType[] FIELD_TYPES = new DateTimeFieldType[] {
DateTimeFieldType.monthOfYear(),
DateTimeFieldType.dayOfMonth(), };
/** The singleton set of field types */
private static final DateTimeFormatter PARSER = new DateTimeFormatterBuilder()
.appendOptional(ISODateTimeFormat.localDateParser().getParser())
.appendOptional(DateTimeFormat.forPattern("--MM-dd").getParser()).toFormatter();
/** The index of the monthOfYear field in the field array */
public static final int MONTH_OF_YEAR = 0;
/** The index of the day field in the field array */
public static final int DAY_OF_MONTH = 1;
//-----------------------------------------------------------------------
/**
* Obtains a {@code MonthDay} set to the current system millisecond time
* using <code>ISOChronology</code> in the default time zone.
* The resulting object does not use the zone.
*
* @return the current month-day, not null
* @since 2.0
*/
public static MonthDay now() {
return new MonthDay();
}
/**
* Obtains a {@code MonthDay} set to the current system millisecond time
* using <code>ISOChronology</code> in the specified time zone.
* The resulting object does not use the zone.
*
* @param zone the time zone, not null
* @return the current month-day, not null
* @since 2.0
*/
public static MonthDay now(DateTimeZone zone) {
if (zone == null) {
throw new NullPointerException("Zone must not be null");
}
return new MonthDay(zone);
}
/**
* Obtains a {@code MonthDay} set to the current system millisecond time
* using the specified chronology.
* The resulting object does not use the zone.
*
* @param chronology the chronology, not null
* @return the current month-day, not null
* @since 2.0
*/
public static MonthDay now(Chronology chronology) {
if (chronology == null) {
throw new NullPointerException("Chronology must not be null");
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>, chronology);
}
/**
* Constructs a MonthDay from an Object that represents some form of time.
* <p>
* The recognised object types are defined in
* {@link org.joda.time.convert.ConverterManager ConverterManager} and
* include ReadableInstant, String, Calendar and Date.
* The String formats are described by {@link ISODateTimeFormat#localDateParser()}.
* <p>
* The chronology used will be derived from the object, defaulting to ISO.
*
* @param instant the date-time object, null means now
* @throws IllegalArgumentException if the instant is invalid
*/
public MonthDay(Object instant) {
super(instant, null, ISODateTimeFormat.localDateParser());
}
/**
* Constructs a MonthDay from an Object that represents some form of time,
* using the specified chronology.
* <p>
* The recognised object types are defined in
* {@link org.joda.time.convert.ConverterManager ConverterManager} and
* include ReadableInstant, String, Calendar and Date.
* The String formats are described by {@link ISODateTimeFormat#localDateParser()}.
* <p>
* The constructor uses the time zone of the chronology specified.
* Once the constructor is complete, all further calculations are performed
* without reference to a time-zone (by switching to UTC).
* The specified chronology overrides that of the object.
*
* @param instant the date-time object, null means now
* @param chronology the chronology, null means ISO default
* @throws IllegalArgumentException if the instant is invalid
*/
public MonthDay(Object instant, Chronology chronology) {
super(instant, DateTimeUtils.getChronology(chronology), ISODateTimeFormat.localDateParser());
}
/**
* Constructs a MonthDay with specified year and month
* using <code>ISOChronology</code>.
* <p>
* The constructor uses the no time zone initialising the fields as provided.
* Once the constructor is complete, all further calculations
* are performed without reference to a time-zone (by switching to UTC).
*
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
*/
public MonthDay(int monthOfYear, int dayOfMonth) {
this(monthOfYear, dayOfMonth, null);
}
/**
* Constructs an instance set to the specified monthOfYear and dayOfMonth
* using the specified chronology, whose zone is ignored.
* <p>
* If the chronology is null, <code>ISOChronology</code> is used.
* <p>
* The constructor uses the time zone of the chronology specified.
* Once the constructor is complete, all further calculations are performed
* without reference to a time-zone (by switching to UTC).
*
* @param monthOfYear the month
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> of the year
* @param dayOfMonth the day of the month
* @param chronology the chronology, null means ISOChronology in the default zone
*/
public MonthDay(int monthOfYear, int dayOfMonth, Chronology chronology) {
super(new int[] {monthOfYear, dayOfMonth}, chronology);
}
/**
* Constructs a MonthDay with chronology from this instance and new values.
*
* @param partial the partial to base this new instance on
* @param values the new set of values
*/
MonthDay(MonthDay partial, int[] values) {
super(partial, values);
}
/**
* Constructs a MonthDay with values from this instance and a new chronology.
*
* @param partial the partial to base this new instance on
* @param chrono the new chronology
*/
MonthDay(MonthDay partial, Chronology chrono) {
super(partial, chrono);
}
/**
* Handle broken serialization from other tools.
* @return the resolved object, not null
*/
private Object readResolve() {
if (DateTimeZone.UTC.equals(getChronology().getZone()) == false) {
return new MonthDay(this, getChronology().withUTC());
}
return this;
}
//-----------------------------------------------------------------------
/**
* Gets the number of fields in this partial, which is two.
* The supported fields are MonthOfYear and DayOfMonth.
* Note that only these fields may be queried.
*
* @return the field count, two
*/
public int size() {
return 2;
}
/**
* Gets the field for a specific index in the chronology specified.
* <p>
* This method must not use any instance variables.
*
* @param index the index to retrieve
* @param chrono the chronology to use
* @return the field, never null
*/
protected DateTimeField getField(int index, Chronology chrono) {
switch (index) {
case MONTH_OF_YEAR:
return chrono.monthOfYear();
case DAY_OF_MONTH:
return chrono.dayOfMonth();
default:
throw new IndexOutOfBoundsException("Invalid index: " + index);
}
}
/**
* Gets the field type at the specified index.
*
* @param index the index to retrieve
* @return the field at the specified index, never null
* @throws IndexOutOfBoundsException if the index is invalid
*/
public DateTimeFieldType getFieldType(int index) {
return FIELD_TYPES[index];
}
/**
* Gets an array of the field type of each of the fields that this partial supports.
* <p>
* The fields are returned largest to smallest, Month, Day.
*
* @return the array of field types (cloned), largest to smallest, never null
*/
public DateTimeFieldType[] getFieldTypes() {
return
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> (DateTimeFieldType[]) FIELD_TYPES.clone();
}
//-----------------------------------------------------------------------
/**
* Returns a copy of this month-day with the specified chronology.
* This instance is immutable and unaffected by this method call.
* <p>
* This method retains the values of the fields, thus the result will
* typically refer to a different instant.
* <p>
* The time zone of the specified chronology is ignored, as MonthDay
* operates without a time zone.
*
* @param newChronology the new chronology, null means ISO
* @return a copy of this month-day with a different chronology, never null
* @throws IllegalArgumentException if the values are invalid for the new chronology
*/
public MonthDay withChronologyRetainFields(Chronology newChronology) {
newChronology = DateTimeUtils.getChronology(newChronology);
newChronology = newChronology.withUTC();
if (newChronology == getChronology()) {
return this;
} else {
MonthDay newMonthDay = new MonthDay(this, newChronology);
newChronology.validate(newMonthDay, getValues());
return newMonthDay;
}
}
/**
* Returns a copy of this month-day with the specified field set to a new value.
* <p>
* For example, if the field type is <code>dayOfMonth</code> then the day
* would be changed in the returned instance.
* <p>
* These three lines are equivalent:
* <pre>
* MonthDay updated = md.withField(DateTimeFieldType.dayOfMonth(), 6);
* MonthDay updated = md.dayOfMonth().setCopy(6);
* MonthDay updated = md.property(DateTimeFieldType.dayOfMonth()).setCopy(6);
* </pre>
*
* @param fieldType the field type to set, not null
* @param value the value to set
* @return a copy of this instance with the field set, never null
* @throws IllegalArgumentException if the value is null or invalid
*/
public MonthDay withField(DateTimeFieldType fieldType, int value) {
int index = indexOfSupported(fieldType);
if (value == getValue(index)) {
return this;
}
int[] newValues = getValues();
newValues = getField(index).set(this, index, newValues, value);
return new MonthDay(this, newValues);
}
/**
* Returns a copy of this month-day with the value of the specified field increased.
* <p>
* If the addition is zero, then <code>this</code> is returned.
* <p>
* These three lines are equivalent:
* <pre>
* MonthDay added = md.withFieldAdded(DurationFieldType.days(), 6);
* MonthDay added = md.plusDays
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(6);
* MonthDay added = md.dayOfMonth().addToCopy(6);
* </pre>
*
* @param fieldType the field type to add to, not null
* @param amount the amount to add
* @return a copy of this instance with the field updated, never null
* @throws IllegalArgumentException if the value is null or invalid
* @throws ArithmeticException if the new date-time exceeds the capacity
*/
public MonthDay withFieldAdded(DurationFieldType fieldType, int amount) {
int index = indexOfSupported(fieldType);
if (amount == 0) {
return this;
}
int[] newValues = getValues();
newValues = getField(index).add(this, index, newValues, amount);
return new MonthDay(this, newValues);
}
/**
* Returns a copy of this month-day with the specified period added.
* <p>
* If the addition is zero, then <code>this</code> is returned.
* Fields in the period that aren't present in the partial are ignored.
* <p>
* This method is typically used to add multiple copies of complex
* period instances. Adding one field is best achieved using methods
* like {@link #withFieldAdded(DurationFieldType, int)}
* or {@link #plusMonths(int)}.
*
* @param period the period to add to this one, null means zero
* @param scalar the amount of times to add, such as -1 to subtract once
* @return a copy of this instance with the period added, never null
* @throws ArithmeticException if the new date-time exceeds the capacity
*/
public MonthDay withPeriodAdded(ReadablePeriod period, int scalar) {
if (period == null || scalar == 0) {
return this;
}
int[] newValues = getValues();
for (int i = 0; i < period.size(); i++) {
DurationFieldType fieldType = period.getFieldType(i);
int index = indexOf(fieldType);
if (index >= 0) {
newValues = getField(index).add(this, index, newValues,
FieldUtils.safeMultiply(period.getValue(i), scalar));
}
}
return new MonthDay(this, newValues);
}
//-----------------------------------------------------------------------
/**
* Returns a copy of this month-day with the specified period added.
* <p>
* If the amount is zero or null, then <code>this</code> is returned.
* <p>
* This method is typically used to add complex period instances.
* Adding one field is best achieved using methods
* like {@link #plusMonths(int)}.
*
* @param period the duration to add to this one, null means zero
* @return a copy of this instance with the period added, never null
* @throws ArithmeticException if the new month-day exceeds the capacity
*/
public MonthDay plus(ReadablePeriod period) {
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> necessary.
* <p>
* The following three lines are identical in effect:
* <pre>
* MonthDay subtracted = md.minusMonths(6);
* MonthDay subtracted = md.minus(Period.months(6));
* MonthDay subtracted = md.withFieldAdded(DurationFieldType.months(), -6);
* </pre>
*
* @param months the amount of months to subtract, may be negative
* @return the new month-day minus the increased months, never null
*/
public MonthDay minusMonths(int months) {
return withFieldAdded(DurationFieldType.months(), FieldUtils.safeNegate(months));
}
/**
* Returns a copy of this month-day minus the specified number of months.
* <p>
* This month-day instance is immutable and unaffected by this method call.
* The month will wrap at the end of the year from January to December.
* <p>
* The following three lines are identical in effect:
* <pre>
* MonthDay subtracted = md.minusDays(6);
* MonthDay subtracted = md.minus(Period.days(6));
* MonthDay subtracted = md.withFieldAdded(DurationFieldType.days(), -6);
* </pre>
*
* @param days the amount of days to subtract, may be negative
* @return the new month-day minus the increased days, never null
*/
public MonthDay minusDays(int days) {
return withFieldAdded(DurationFieldType.days(), FieldUtils.safeNegate(days));
}
//-----------------------------------------------------------------------
/**
* Converts this object to a LocalDate with the same month-day and chronology.
*
* @param year the year to use, valid for chronology
* @return a LocalDate with the same month-day and chronology, never null
*/
public LocalDate toLocalDate(int year) {
return new LocalDate(year, getMonthOfYear(), getDayOfMonth(), getChronology());
}
//-----------------------------------------------------------------------
/**
* Get the month of year field value.
*
* @return the month of year
*/
public int getMonthOfYear() {
return getValue(MONTH_OF_YEAR);
}
/**
* Get the day of month field value.
*
* @return the day of month
*/
public int getDayOfMonth() {
return getValue(DAY_OF_MONTH);
}
//-----------------------------------------------------------------------
/**
* Returns a copy of this month-day with the month of year field updated.
* <p>
* MonthDay is immutable, so there are no set methods.
* Instead, this method returns a new instance with the value of
* month of year changed.
*
* @param monthOfYear the month of year to set
* @return a copy of this object with the field set, never null
* @throws IllegalArgumentException if the value is invalid
*/
public MonthDay withMonthOfYear(int
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> monthOfYear) {
int[] newValues = getValues();
newValues = getChronology().monthOfYear().set(this, MONTH_OF_YEAR, newValues, monthOfYear);
return new MonthDay(this, newValues);
}
/**
* Returns a copy of this month-day with the day of month field updated.
* <p>
* MonthDay is immutable, so there are no set methods.
* Instead, this method returns a new instance with the value of
* day of month changed.
*
* @param dayOfMonth the day of month to set
* @return a copy of this object with the field set, never null
* @throws IllegalArgumentException if the value is invalid
*/
public MonthDay withDayOfMonth(int dayOfMonth) {
int[] newValues = getValues();
newValues = getChronology().dayOfMonth().set(this, DAY_OF_MONTH, newValues, dayOfMonth);
return new MonthDay(this, newValues);
}
//-----------------------------------------------------------------------
/**
* Gets the property object for the specified type, which contains
* many useful methods.
*
* @param type the field type to get the property for
* @return the property object
* @throws IllegalArgumentException if the field is null or unsupported
*/
public Property property(DateTimeFieldType type) {
return new Property(this, indexOfSupported(type));
}
//-----------------------------------------------------------------------
/**
* Get the month of year field property which provides access to advanced functionality.
*
* @return the month of year property
*/
public Property monthOfYear() {
return new Property(this, MONTH_OF_YEAR);
}
/**
* Get the day of month field property which provides access to advanced functionality.
*
* @return the day of month property
*/
public Property dayOfMonth() {
return new Property(this, DAY_OF_MONTH);
}
//-----------------------------------------------------------------------
/**
* Output the month-day in ISO8601 format (--MM-dd).
*
* @return ISO8601 time formatted string.
*/
@ToString
public String toString() {
List<DateTimeFieldType> fields = new ArrayList<DateTimeFieldType>();
fields.add(DateTimeFieldType.monthOfYear());
fields.add(DateTimeFieldType.dayOfMonth());
return ISODateTimeFormat.forFields(fields, true, true).print(this);
}
/**
* Output the month-day using the specified format pattern.
*
* @param pattern the pattern specification, null means use <code>toString</code>
* @see org.joda.time.format.DateTimeFormat
*/
public String toString(String pattern) {
if (pattern == null) {
return toString();
}
return DateTimeFormat.forPattern(pattern).print(this);
}
/**
* Output the month-day using the specified format pattern.
*
* @param pattern the pattern specification, null means use <code>toString</code>
* @
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>param locale Locale to use, null means default
* @see org.joda.time.format.DateTimeFormat
*/
public String toString(String pattern, Locale locale) throws IllegalArgumentException {
if (pattern == null) {
return toString();
}
return DateTimeFormat.forPattern(pattern).withLocale(locale).print(this);
}
//-----------------------------------------------------------------------
/**
* The property class for <code>MonthDay</code>.
* <p>
* This class binds a <code>YearMonth</code> to a <code>DateTimeField</code>.
*
* @author Chris Pheby
* @since 2.0
*/
public static class Property extends AbstractPartialFieldProperty implements Serializable {
/** Serialization version */
private static final long serialVersionUID = 5727734012190224363L;
/** The partial */
private final MonthDay iBase;
/** The field index */
private final int iFieldIndex;
/**
* Constructs a property.
*
* @param partial the partial instance
* @param fieldIndex the index in the partial
*/
Property(MonthDay partial, int fieldIndex) {
super();
iBase = partial;
iFieldIndex = fieldIndex;
}
/**
* Gets the field that this property uses.
*
* @return the field
*/
public DateTimeField getField() {
return iBase.getField(iFieldIndex);
}
/**
* Gets the partial that this property belongs to.
*
* @return the partial
*/
protected ReadablePartial getReadablePartial() {
return iBase;
}
/**
* Gets the partial that this property belongs to.
*
* @return the partial
*/
public MonthDay getMonthDay() {
return iBase;
}
/**
* Gets the value of this field.
*
* @return the field value
*/
public int get() {
return iBase.getValue(iFieldIndex);
}
//-----------------------------------------------------------------------
/**
* Adds to the value of this field in a copy of this MonthDay.
* <p>
* The value will be added to this field. If the value is too large to be
* added solely to this field then it will affect larger fields.
* Smaller fields are unaffected.
* <p>
* The MonthDay attached to this property is unchanged by this call.
* Instead, a new instance is returned.
*
* @param valueToAdd the value to add to the field in the copy
* @return a copy of the MonthDay with the field value changed
* @throws IllegalArgumentException if the value isn't valid
*/
public MonthDay addToCopy(int valueToAdd) {
int[] newValues = iBase.getValues();
newValues = getField().add(iBase, iFieldIndex, newValues, valueToAdd);
return new MonthDay(iBase, newValues);
}
/**
* Adds
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2009 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import java.io.Serializable;
import org.joda.time.DurationField;
import org.joda.time.DurationFieldType;
/**
* Duration field class representing a field with a fixed unit length of one
* millisecond.
* <p>
* MillisDurationField is thread-safe and immutable.
*
* @author Brian S O'Neill
* @since 1.0
*/
public final class MillisDurationField extends DurationField implements Serializable {
/** Serialization lock. */
private static final long serialVersionUID = 2656707858124633367L;
/** Singleton instance. */
public static final DurationField INSTANCE = new MillisDurationField();
/**
* Restricted constructor.
*/
private MillisDurationField() {
super();
}
//------------------------------------------------------------------------
public DurationFieldType getType() {
return DurationFieldType.millis();
}
public String getName() {
return "millis";
}
/**
* Returns true as this field is supported.
*
* @return true always
*/
public boolean isSupported() {
return true;
}
/**
* Returns true as this field is precise.
*
* @return true always
*/
public final boolean isPrecise() {
return true;
}
/**
* Returns the amount of milliseconds per unit value of this field.
*
* @return one always
*/
public final long getUnitMillis() {
return 1;
}
//------------------------------------------------------------------------
public int getValue(long duration) {
return FieldUtils.safeToInt(duration);
}
public long getValueAsLong(long duration) {
return duration;
}
public int getValue(long duration, long instant) {
return FieldUtils.safeToInt(duration);
}
public long getValueAsLong(long duration, long instant) {
return duration;
}
public long getMillis(int value) {
return value;
}
public long getMillis(long value) {
return value;
}
public long getMillis(int value, long instant) {
return value;
}
public long getMillis(long value, long instant) {
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
return value;
}
public long add(long instant, int value) {
return FieldUtils.safeAdd(instant, value);
}
public long add(long instant, long value) {
return FieldUtils.safeAdd(instant, value);
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
return FieldUtils.safeToInt(FieldUtils.safeSubtract(minuendInstant, subtrahendInstant));
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
return FieldUtils.safeSubtract(minuendInstant, subtrahendInstant);
}
//------------------------------------------------------------------------
public int compareTo(DurationField otherField) {
long otherMillis = otherField.getUnitMillis();
long thisMillis = getUnitMillis();
// cannot do (thisMillis - otherMillis) as can overflow
if (thisMillis == otherMillis) {
return 0;
}
if (thisMillis < otherMillis) {
return -1;
} else {
return 1;
}
}
public boolean equals(Object obj) {
if (obj instanceof MillisDurationField) {
return getUnitMillis() == ((MillisDurationField) obj).getUnitMillis();
}
return false;
}
public int hashCode() {
return (int) getUnitMillis();
}
/**
* Get a suitable debug string.
*
* @return debug string
*/
public String toString() {
return "DurationField[millis]";
}
/**
* Deserialize to the singleton.
*/
private Object readResolve() {
return INSTANCE;
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.ReadablePartial;
import org.joda.time.field.DecoratedDateTimeField;
import org.joda.time.field.FieldUtils;
/**
* Provides time calculations for the year of era component of time.
*
* @author Brian S O'Neill
* @since 1.0
*/
final class GJYearOfEraDateTimeField extends DecoratedDateTimeField {
private static final long serialVersionUID = -5961050944769862059L;
private final BasicChronology iChronology;
/**
* Restricted constructor.
*/
GJYearOfEraDateTimeField(DateTimeField yearField, BasicChronology chronology) {
super(yearField, DateTimeFieldType.yearOfEra());
iChronology = chronology;
}
public int get(long instant) {
int year = getWrappedField().get(instant);
if (year <= 0) {
year = 1 - year;
}
return year;
}
public long add(long instant, int years) {
return getWrappedField().add(instant, years);
}
public long add(long instant, long years) {
return getWrappedField().add(instant, years);
}
public long addWrapField(long instant, int years) {
return getWrappedField().addWrapField(instant, years);
}
public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int years) {
return getWrappedField().addWrapField(instant, fieldIndex, values, years);
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
return getWrappedField().getDifference(minuendInstant, subtrahendInstant);
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant);
}
/**
* Set the year component of the
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import java.util.Locale;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.IllegalFieldValueException;
import org.joda.time.ReadablePartial;
/**
* BaseDateTimeField provides the common behaviour for DateTimeField
* implementations.
* <p>
* This class should generally not be used directly by API users. The
* DateTimeField class should be used when different kinds of DateTimeField
* objects are to be referenced.
* <p>
* BaseDateTimeField is thread-safe and immutable, and its subclasses must
* be as well.
*
* @author Brian S O'Neill
* @since 1.0
* @see DecoratedDateTimeField
*/
public abstract class BaseDateTimeField extends DateTimeField {
/** The field type. */
private final DateTimeFieldType iType;
/**
* Constructor.
*/
protected BaseDateTimeField(DateTimeFieldType type) {
super();
if (type == null) {
throw new IllegalArgumentException("The type must not be null");
}
iType = type;
}
public final DateTimeFieldType getType() {
return iType;
}
public final String getName() {
return iType.getName();
}
/**
* @return true always
*/
public final boolean isSupported() {
return true;
}
// Main access API
//------------------------------------------------------------------------
/**
* Get the value of this field from the milliseconds.
*
* @param instant the milliseconds from 1970-01-01T00:00:00Z to query
* @return the value of the field, in the units of the field
*/
public abstract int get(long instant);
//-----------------------------------------------------------------------
/**
* Get the human-readable, text value of this field from the milliseconds.
* If the specified locale is null, the default locale is used.
* <p>
* The default implementation returns getAsText(get(instant), locale).
*
* @param instant the milliseconds from 1970-01-01T00:00:00
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>FromString
public static DateTimeZone forID(String id) {
if (id == null) {
return getDefault();
}
if (id.equals("UTC")) {
return DateTimeZone.UTC;
}
DateTimeZone zone = cProvider.getZone(id);
if (zone != null) {
return zone;
}
if (id.startsWith("+") || id.startsWith("-")) {
int offset = parseOffset(id);
if (offset == 0L) {
return DateTimeZone.UTC;
} else {
id = printOffset(offset);
return fixedOffsetZone(id, offset);
}
}
throw new IllegalArgumentException("The datetime zone id '" + id + "' is not recognised");
}
/**
* Gets a time zone instance for the specified offset to UTC in hours.
* This method assumes standard length hours.
* <p>
* This factory is a convenient way of constructing zones with a fixed offset.
*
* @param hoursOffset the offset in hours from UTC
* @return the DateTimeZone object for the offset
* @throws IllegalArgumentException if the offset is too large or too small
*/
public static DateTimeZone forOffsetHours(int hoursOffset) throws IllegalArgumentException {
return forOffsetHoursMinutes(hoursOffset, 0);
}
/**
* Gets a time zone instance for the specified offset to UTC in hours and minutes.
* This method assumes 60 minutes in an hour, and standard length minutes.
* <p>
* This factory is a convenient way of constructing zones with a fixed offset.
* The minutes value is always positive and in the range 0 to 59.
* If constructed with the values (-2, 30), the resulting zone is '-02:30'.
*
* @param hoursOffset the offset in hours from UTC
* @param minutesOffset the offset in minutes from UTC, must be between 0 and 59 inclusive
* @return the DateTimeZone object for the offset
* @throws IllegalArgumentException if the offset or minute is too large or too small
*/
public static DateTimeZone forOffsetHoursMinutes(int hoursOffset, int minutesOffset) throws IllegalArgumentException {
if (hoursOffset == 0 && minutesOffset == 0) {
return DateTimeZone.UTC;
}
if (minutesOffset < 0 || minutesOffset > 59) {
throw new IllegalArgumentException("Minutes out of range: " + minutesOffset);
}
int offset = 0;
try {
int hoursInMinutes = FieldUtils.safeMultiply(hoursOffset, 60);
if (hoursInMinutes < 0) {
minutesOffset = FieldUtils.safeAdd(hoursInMinutes, -minutesOffset);
} else {
minutesOffset = FieldUtils.safeAdd(hoursInMinutes, minutesOffset);
}
offset = FieldUtils.safeMultiply(minutesOffset, DateTimeConstants.MILLIS_PER_MINUTE);
} catch (ArithmeticException ex) {
throw new IllegalArgumentException("Offset is too large
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>");
}
return forOffsetMillis(offset);
}
/**
* Gets a time zone instance for the specified offset to UTC in milliseconds.
*
* @param millisOffset the offset in millis from UTC
* @return the DateTimeZone object for the offset
*/
public static DateTimeZone forOffsetMillis(int millisOffset) {
String id = printOffset(millisOffset);
return fixedOffsetZone(id, millisOffset);
}
/**
* Gets a time zone instance for a JDK TimeZone.
* <p>
* DateTimeZone only accepts a subset of the IDs from TimeZone. The
* excluded IDs are the short three letter form (except UTC). This
* method will attempt to convert between time zones created using the
* short IDs and the full version.
* <p>
* This method is not designed to parse time zones with rules created by
* applications using <code>SimpleTimeZone</code> directly.
*
* @param zone the zone to convert, null means default
* @return the DateTimeZone object for the zone
* @throws IllegalArgumentException if the zone is not recognised
*/
public static DateTimeZone forTimeZone(TimeZone zone) {
if (zone == null) {
return getDefault();
}
final String id = zone.getID();
if (id.equals("UTC")) {
return DateTimeZone.UTC;
}
// Convert from old alias before consulting provider since they may differ.
DateTimeZone dtz = null;
String convId = getConvertedId(id);
if (convId != null) {
dtz = cProvider.getZone(convId);
}
if (dtz == null) {
dtz = cProvider.getZone(id);
}
if (dtz != null) {
return dtz;
}
// Support GMT+/-hh:mm formats
if (convId == null) {
convId = zone.getID();
if (convId.startsWith("GMT+") || convId.startsWith("GMT-")) {
convId = convId.substring(3);
int offset = parseOffset(convId);
if (offset == 0L) {
return DateTimeZone.UTC;
} else {
convId = printOffset(offset);
return fixedOffsetZone(convId, offset);
}
}
}
throw new IllegalArgumentException("The datetime zone id '" + id + "' is not recognised");
}
//-----------------------------------------------------------------------
/**
* Gets the zone using a fixed offset amount.
*
* @param id the zone id
* @param offset the offset in millis
* @return the zone
*/
private static synchronized DateTimeZone fixedOffsetZone(String id, int offset) {
if (offset == 0) {
return DateTimeZone.UTC;
}
if (iFixedOffsetCache == null) {
iFixedOffsetCache = new HashMap<String, SoftReference<DateTimeZone>>();
}
DateTimeZone zone;
Reference<DateTimeZone> ref = i
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>FixedOffsetCache.get(id);
if (ref != null) {
zone = ref.get();
if (zone != null) {
return zone;
}
}
zone = new FixedDateTimeZone(id, null, offset, offset);
iFixedOffsetCache.put(id, new SoftReference<DateTimeZone>(zone));
return zone;
}
/**
* Gets all the available IDs supported.
*
* @return an unmodifiable Set of String IDs
*/
public static Set<String> getAvailableIDs() {
return cAvailableIDs;
}
//-----------------------------------------------------------------------
/**
* Gets the zone provider factory.
* <p>
* The zone provider is a pluggable instance factory that supplies the
* actual instances of DateTimeZone.
*
* @return the provider
*/
public static Provider getProvider() {
return cProvider;
}
/**
* Sets the zone provider factory.
* <p>
* The zone provider is a pluggable instance factory that supplies the
* actual instances of DateTimeZone.
*
* @param provider provider to use, or null for default
* @throws SecurityException if you do not have the permission DateTimeZone.setProvider
* @throws IllegalArgumentException if the provider is invalid
*/
public static void setProvider(Provider provider) throws SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new JodaTimePermission("DateTimeZone.setProvider"));
}
setProvider0(provider);
}
/**
* Sets the zone provider factory without performing the security check.
*
* @param provider provider to use, or null for default
* @throws IllegalArgumentException if the provider is invalid
*/
private static void setProvider0(Provider provider) {
if (provider == null) {
provider = getDefaultProvider();
}
Set<String> ids = provider.getAvailableIDs();
if (ids == null || ids.size() == 0) {
throw new IllegalArgumentException
("The provider doesn't have any available ids");
}
if (!ids.contains("UTC")) {
throw new IllegalArgumentException("The provider doesn't support UTC");
}
if (!UTC.equals(provider.getZone("UTC"))) {
throw new IllegalArgumentException("Invalid UTC zone provided");
}
cProvider = provider;
cAvailableIDs = ids;
}
/**
* Gets the default zone provider.
* <p>
* Tries the system property <code>org.joda.time.DateTimeZone.Provider</code>.
* Then tries a <code>ZoneInfoProvider</code> using the data in <code>org/joda/time/tz/data</code>.
* Then uses <code>UTCProvider</code>.
*
* @return the default name provider
*/
private static Provider getDefaultProvider() {
Provider provider = null;
try {
String providerClass =
System.getProperty("org.joda.time.DateTimeZone.Provider");
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>1970-01-01T00:00:00Z
*/
public abstract long previousTransition(long instant);
// Basic methods
//--------------------------------------------------------------------
/**
* Get the datetime zone as a {@link java.util.TimeZone}.
*
* @return the closest matching TimeZone object
*/
public java.util.TimeZone toTimeZone() {
return java.util.TimeZone.getTimeZone(iID);
}
/**
* Compare this datetime zone with another.
*
* @param object the object to compare with
* @return true if equal, based on the ID and all internal rules
*/
public abstract boolean equals(Object object);
/**
* Gets a hash code compatable with equals.
*
* @return suitable hashcode
*/
public int hashCode() {
return 57 + getID().hashCode();
}
/**
* Gets the datetime zone as a string, which is simply its ID.
* @return the id of the zone
*/
public String toString() {
return getID();
}
/**
* By default, when DateTimeZones are serialized, only a "stub" object
* referring to the id is written out. When the stub is read in, it
* replaces itself with a DateTimeZone object.
* @return a stub object to go in the stream
*/
protected Object writeReplace() throws ObjectStreamException {
return new Stub(iID);
}
/**
* Used to serialize DateTimeZones by id.
*/
private static final class Stub implements Serializable {
/** Serialization lock. */
private static final long serialVersionUID = -6471952376487863581L;
/** The ID of the zone. */
private transient String iID;
/**
* Constructor.
* @param id the id of the zone
*/
Stub(String id) {
iID = id;
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeUTF(iID);
}
private void readObject(ObjectInputStream in) throws IOException {
iID = in.readUTF();
}
private Object readResolve() throws ObjectStreamException {
return forID(iID);
}
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> 7200000)
* .addRecurringSavings("PDT", 3600000, 1974, 1974, 'w', 1, 6, 0, false, 7200000)
* .addRecurringSavings("PDT", 3600000, 1975, 1975, 'w', 2, 23, 0, false, 7200000)
* .addRecurringSavings("PDT", 3600000, 1976, 1986, 'w', 4, -1, 7, false, 7200000)
* .addRecurringSavings("PDT", 3600000, 1987, 2147483647, 'w', 4, 1, 7, true, 7200000)
* .toDateTimeZone("America/Los_Angeles", true);
* </pre>
*
* @author Brian S O'Neill
* @see ZoneInfoCompiler
* @see ZoneInfoProvider
* @since 1.0
*/
public class DateTimeZoneBuilder {
/**
* Decodes a built DateTimeZone from the given stream, as encoded by
* writeTo.
*
* @param in input stream to read encoded DateTimeZone from.
* @param id time zone id to assign
*/
public static DateTimeZone readFrom(InputStream in, String id) throws IOException {
if (in instanceof DataInput) {
return readFrom((DataInput)in, id);
} else {
return readFrom((DataInput)new DataInputStream(in), id);
}
}
/**
* Decodes a built DateTimeZone from the given stream, as encoded by
* writeTo.
*
* @param in input stream to read encoded DateTimeZone from.
* @param id time zone id to assign
*/
public static DateTimeZone readFrom(DataInput in, String id) throws IOException {
switch (in.readUnsignedByte()) {
case 'F':
DateTimeZone fixed = new FixedDateTimeZone
(id, in.readUTF(), (int)readMillis(in), (int)readMillis(in));
if (fixed.equals(DateTimeZone.UTC)) {
fixed = DateTimeZone.UTC;
}
return fixed;
case 'C':
return CachedDateTimeZone.forZone(PrecalculatedZone.readFrom(in, id));
case 'P':
return PrecalculatedZone.readFrom(in, id);
default:
throw new IOException("Invalid encoding");
}
}
/**
* Millisecond encoding formats:
*
* upper two bits units field length approximate range
* ---------------------------------------------------------------
* 00
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>:
// Form 01 (30 bits effective precision)
v = (v << (32 - 6)) >> (32 - 30);
v |= (in.readUnsignedByte()) << 16;
v |= (in.readUnsignedByte()) << 8;
v |= (in.readUnsignedByte());
return v * 60000L;
case 2:
// Form 10 (38 bits effective precision)
long w = (((long)v) << (64 - 6)) >> (64 - 38);
w |= (in.readUnsignedByte()) << 24;
w |= (in.readUnsignedByte()) << 16;
w |= (in.readUnsignedByte()) << 8;
w |= (in.readUnsignedByte());
return w * 1000L;
case 3:
// Form 11 (64 bits effective precision)
return in.readLong();
}
}
private static DateTimeZone buildFixedZone(String id, String nameKey,
int wallOffset, int standardOffset) {
if ("UTC".equals(id) && id.equals(nameKey) &&
wallOffset == 0 && standardOffset == 0) {
return DateTimeZone.UTC;
}
return new FixedDateTimeZone(id, nameKey, wallOffset, standardOffset);
}
// List of RuleSets.
private final ArrayList<RuleSet> iRuleSets;
public DateTimeZoneBuilder() {
iRuleSets = new ArrayList<RuleSet>(10);
}
/**
* Adds a cutover for added rules. The standard offset at the cutover
* defaults to 0. Call setStandardOffset afterwards to change it.
*
* @param year the year of cutover
* @param mode 'u' - cutover is measured against UTC, 'w' - against wall
* offset, 's' - against standard offset
* @param monthOfYear the month from 1 (January) to 12 (December)
* @param dayOfMonth if negative, set to ((last day of month) - ~dayOfMonth).
* For example, if -1, set to last day of month
* @param dayOfWeek from 1 (Monday) to 7 (Sunday), if 0 then ignore
* @param advanceDayOfWeek if dayOfMonth does not fall on dayOfWeek, advance to
* dayOfWeek when true, retreat when false.
* @param millisOfDay additional precision for specifying time of day of cutover
*/
public DateTimeZoneBuilder addCutover(int year,
char mode,
int monthOfYear,
int dayOfMonth,
int dayOfWeek,
boolean advanceDayOfWeek,
int millisOfDay)
{
if (iRuleSets.size() > 0) {
OfYear ofYear = new OfYear
(mode, monthOfYear, dayOfMonth
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>, dayOfWeek, advanceDayOfWeek, millisOfDay);
RuleSet lastRuleSet = iRuleSets.get(iRuleSets.size() - 1);
lastRuleSet.setUpperLimit(year, ofYear);
}
iRuleSets.add(new RuleSet());
return this;
}
/**
* Sets the standard offset to use for newly added rules until the next
* cutover is added.
* @param standardOffset the standard offset in millis
*/
public DateTimeZoneBuilder setStandardOffset(int standardOffset) {
getLastRuleSet().setStandardOffset(standardOffset);
return this;
}
/**
* Set a fixed savings rule at the cutover.
*/
public DateTimeZoneBuilder setFixedSavings(String nameKey, int saveMillis) {
getLastRuleSet().setFixedSavings(nameKey, saveMillis);
return this;
}
/**
* Add a recurring daylight saving time rule.
*
* @param nameKey the name key of new rule
* @param saveMillis the milliseconds to add to standard offset
* @param fromYear the first year that rule is in effect, MIN_VALUE indicates
* beginning of time
* @param toYear the last year (inclusive) that rule is in effect, MAX_VALUE
* indicates end of time
* @param mode 'u' - transitions are calculated against UTC, 'w' -
* transitions are calculated against wall offset, 's' - transitions are
* calculated against standard offset
* @param monthOfYear the month from 1 (January) to 12 (December)
* @param dayOfMonth if negative, set to ((last day of month) - ~dayOfMonth).
* For example, if -1, set to last day of month
* @param dayOfWeek from 1 (Monday) to 7 (Sunday), if 0 then ignore
* @param advanceDayOfWeek if dayOfMonth does not fall on dayOfWeek, advance to
* dayOfWeek when true, retreat when false.
* @param millisOfDay additional precision for specifying time of day of transitions
*/
public DateTimeZoneBuilder addRecurringSavings(String nameKey, int saveMillis,
int fromYear, int toYear,
char mode,
int monthOfYear,
int dayOfMonth,
int dayOfWeek,
boolean advanceDayOfWeek,
int millisOfDay)
{
if (fromYear <= toYear) {
OfYear ofYear = new OfYear
(mode, monthOfYear, dayOfMonth, dayOfWeek, advanceDayOfWeek, millisOfDay);
Recurrence recurrence = new Recurrence(ofYear, nameKey, saveMillis);
Rule rule = new Rule(recurrence, fromYear, toYear);
getLastRuleSet().addRule(rule);
}
return this;
}
private RuleSet getLastRuleSet() {
if (iRuleSets.size() == 0) {
addCutover(Integer.MIN_
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>.readUnsignedByte(),
(int)in.readByte(),
(int)in.readUnsignedByte(),
in.readBoolean(),
(int)readMillis(in));
}
// Is 'u', 'w', or 's'.
final char iMode;
final int iMonthOfYear;
final int iDayOfMonth;
final int iDayOfWeek;
final boolean iAdvance;
final int iMillisOfDay;
OfYear(char mode,
int monthOfYear,
int dayOfMonth,
int dayOfWeek, boolean advanceDayOfWeek,
int millisOfDay)
{
if (mode != 'u' && mode != 'w' && mode != 's') {
throw new IllegalArgumentException("Unknown mode: " + mode);
}
iMode = mode;
iMonthOfYear = monthOfYear;
iDayOfMonth = dayOfMonth;
iDayOfWeek = dayOfWeek;
iAdvance = advanceDayOfWeek;
iMillisOfDay = millisOfDay;
}
/**
* @param standardOffset standard offset just before instant
*/
public long setInstant(int year, int standardOffset, int saveMillis) {
int offset;
if (iMode == 'w') {
offset = standardOffset + saveMillis;
} else if (iMode == 's') {
offset = standardOffset;
} else {
offset = 0;
}
Chronology chrono = ISOChronology.getInstanceUTC();
long millis = chrono.year().set(0, year);
millis = chrono.monthOfYear().set(millis, iMonthOfYear);
millis = chrono.millisOfDay().set(millis, iMillisOfDay);
millis = setDayOfMonth(chrono, millis);
if (iDayOfWeek != 0) {
millis = setDayOfWeek(chrono, millis);
}
// Convert from local time to UTC.
return millis - offset;
}
/**
* @param standardOffset standard offset just before next recurrence
*/
public long next(long instant, int standardOffset, int saveMillis) {
int offset;
if (iMode == 'w') {
offset = standardOffset + saveMillis;
} else if (iMode == 's') {
offset = standardOffset;
} else {
offset = 0;
}
// Convert from UTC to local time.
instant += offset;
Chronology chrono = ISOChronology.getInstanceUTC();
long next = chrono.monthOfYear().set(instant, iMonthOfYear);
// Be lenient with millisOfDay.
next = chrono.millisOfDay().set(next, 0);
next = chrono.millisOfDay().add(next, iMillisOfDay);
next = setDayOfMonthNext(chrono, next);
if (iDayOfWeek == 0) {
if (next <= instant) {
next = chrono.year().add(next, 1);
next = setDayOfMonthNext(chrono, next);
}
} else {
next = setDayOfWeek(chrono, next);
if (next <= instant) {
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
next = chrono.year().add(next, 1);
next = chrono.monthOfYear().set(next, iMonthOfYear);
next = setDayOfMonthNext(chrono, next);
next = setDayOfWeek(chrono, next);
}
}
// Convert from local time to UTC.
return next - offset;
}
/**
* @param standardOffset standard offset just before previous recurrence
*/
public long previous(long instant, int standardOffset, int saveMillis) {
int offset;
if (iMode == 'w') {
offset = standardOffset + saveMillis;
} else if (iMode == 's') {
offset = standardOffset;
} else {
offset = 0;
}
// Convert from UTC to local time.
instant += offset;
Chronology chrono = ISOChronology.getInstanceUTC();
long prev = chrono.monthOfYear().set(instant, iMonthOfYear);
// Be lenient with millisOfDay.
prev = chrono.millisOfDay().set(prev, 0);
prev = chrono.millisOfDay().add(prev, iMillisOfDay);
prev = setDayOfMonthPrevious(chrono, prev);
if (iDayOfWeek == 0) {
if (prev >= instant) {
prev = chrono.year().add(prev, -1);
prev = setDayOfMonthPrevious(chrono, prev);
}
} else {
prev = setDayOfWeek(chrono, prev);
if (prev >= instant) {
prev = chrono.year().add(prev, -1);
prev = chrono.monthOfYear().set(prev, iMonthOfYear);
prev = setDayOfMonthPrevious(chrono, prev);
prev = setDayOfWeek(chrono, prev);
}
}
// Convert from local time to UTC.
return prev - offset;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof OfYear) {
OfYear other = (OfYear)obj;
return
iMode == other.iMode &&
iMonthOfYear == other.iMonthOfYear &&
iDayOfMonth == other.iDayOfMonth &&
iDayOfWeek == other.iDayOfWeek &&
iAdvance == other.iAdvance &&
iMillisOfDay == other.iMillisOfDay;
}
return false;
}
/*
public String toString() {
return
"[OfYear]\n" +
"Mode: " + iMode + '\n' +
"MonthOfYear: " + iMonthOfYear + '\n' +
"DayOfMonth: " + iDayOfMonth + '\n' +
"DayOfWeek: " + iDayOfWeek + '\n' +
"AdvanceDayOfWeek: " + iAdvance + '\n' +
"MillisOfDay: " + iMillisOfDay + '\n';
}
*/
public void writeTo(DataOutput out) throws IOException {
out.writeByte(iMode);
out.writeByte(iMonthOfYear);
out.writeByte(iDayOfMonth
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>);
out.writeByte(iDayOfWeek);
out.writeBoolean(iAdvance);
writeMillis(out, iMillisOfDay);
}
/**
* If month-day is 02-29 and year isn't leap, advances to next leap year.
*/
private long setDayOfMonthNext(Chronology chrono, long next) {
try {
next = setDayOfMonth(chrono, next);
} catch (IllegalArgumentException e) {
if (iMonthOfYear == 2 && iDayOfMonth == 29) {
while (chrono.year().isLeap(next) == false) {
next = chrono.year().add(next, 1);
}
next = setDayOfMonth(chrono, next);
} else {
throw e;
}
}
return next;
}
/**
* If month-day is 02-29 and year isn't leap, retreats to previous leap year.
*/
private long setDayOfMonthPrevious(Chronology chrono, long prev) {
try {
prev = setDayOfMonth(chrono, prev);
} catch (IllegalArgumentException e) {
if (iMonthOfYear == 2 && iDayOfMonth == 29) {
while (chrono.year().isLeap(prev) == false) {
prev = chrono.year().add(prev, -1);
}
prev = setDayOfMonth(chrono, prev);
} else {
throw e;
}
}
return prev;
}
private long setDayOfMonth(Chronology chrono, long instant) {
if (iDayOfMonth >= 0) {
instant = chrono.dayOfMonth().set(instant, iDayOfMonth);
} else {
instant = chrono.dayOfMonth().set(instant, 1);
instant = chrono.monthOfYear().add(instant, 1);
instant = chrono.dayOfMonth().add(instant, iDayOfMonth);
}
return instant;
}
private long setDayOfWeek(Chronology chrono, long instant) {
int dayOfWeek = chrono.dayOfWeek().get(instant);
int daysToAdd = iDayOfWeek - dayOfWeek;
if (daysToAdd != 0) {
if (iAdvance) {
if (daysToAdd < 0) {
daysToAdd += 7;
}
} else {
if (daysToAdd > 0) {
daysToAdd -= 7;
}
}
instant = chrono.dayOfWeek().add(instant, daysToAdd);
}
return instant;
}
}
/**
* Extends OfYear with a nameKey and savings.
*/
private static final class Recurrence {
static Recurrence readFrom(DataInput in) throws IOException {
return new Recurrence(OfYear.readFrom(in), in.readUTF(), (int)readMillis(in));
}
final OfYear iOfYear;
final String iNameKey;
final int iSaveMillis;
Recurrence
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(OfYear ofYear, String nameKey, int saveMillis) {
iOfYear = ofYear;
iNameKey = nameKey;
iSaveMillis = saveMillis;
}
public OfYear getOfYear() {
return iOfYear;
}
/**
* @param standardOffset standard offset just before next recurrence
*/
public long next(long instant, int standardOffset, int saveMillis) {
return iOfYear.next(instant, standardOffset, saveMillis);
}
/**
* @param standardOffset standard offset just before previous recurrence
*/
public long previous(long instant, int standardOffset, int saveMillis) {
return iOfYear.previous(instant, standardOffset, saveMillis);
}
public String getNameKey() {
return iNameKey;
}
public int getSaveMillis() {
return iSaveMillis;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Recurrence) {
Recurrence other = (Recurrence)obj;
return
iSaveMillis == other.iSaveMillis &&
iNameKey.equals(other.iNameKey) &&
iOfYear.equals(other.iOfYear);
}
return false;
}
public void writeTo(DataOutput out) throws IOException {
iOfYear.writeTo(out);
out.writeUTF(iNameKey);
writeMillis(out, iSaveMillis);
}
Recurrence rename(String nameKey) {
return new Recurrence(iOfYear, nameKey, iSaveMillis);
}
Recurrence renameAppend(String appendNameKey) {
return rename((iNameKey + appendNameKey).intern());
}
}
/**
* Extends Recurrence with inclusive year limits.
*/
private static final class Rule {
final Recurrence iRecurrence;
final int iFromYear; // inclusive
final int iToYear; // inclusive
Rule(Recurrence recurrence, int fromYear, int toYear) {
iRecurrence = recurrence;
iFromYear = fromYear;
iToYear = toYear;
}
public int getFromYear() {
return iFromYear;
}
public int getToYear() {
return iToYear;
}
public OfYear getOfYear() {
return iRecurrence.getOfYear();
}
public String getNameKey() {
return iRecurrence.getNameKey();
}
public int getSaveMillis() {
return iRecurrence.getSaveMillis();
}
public long next(final long instant, int standardOffset, int saveMillis) {
Chronology chrono = ISOChronology.getInstanceUTC();
final int wallOffset = standardOffset + saveMillis;
long testInstant = instant;
int year;
if (instant == Long.MIN_VALUE) {
year = Integer.MIN_VALUE;
} else {
year = chrono.year().get(instant + wallOffset);
}
if
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> (year < iFromYear) {
// First advance instant to start of from year.
testInstant = chrono.year().set(0, iFromYear) - wallOffset;
// Back off one millisecond to account for next recurrence
// being exactly at the beginning of the year.
testInstant -= 1;
}
long next = iRecurrence.next(testInstant, standardOffset, saveMillis);
if (next > instant) {
year = chrono.year().get(next + wallOffset);
if (year > iToYear) {
// Out of range, return original value.
next = instant;
}
}
return next;
}
}
private static final class Transition {
private final long iMillis;
private final String iNameKey;
private final int iWallOffset;
private final int iStandardOffset;
Transition(long millis, Transition tr) {
iMillis = millis;
iNameKey = tr.iNameKey;
iWallOffset = tr.iWallOffset;
iStandardOffset = tr.iStandardOffset;
}
Transition(long millis, Rule rule, int standardOffset) {
iMillis = millis;
iNameKey = rule.getNameKey();
iWallOffset = standardOffset + rule.getSaveMillis();
iStandardOffset = standardOffset;
}
Transition(long millis, String nameKey,
int wallOffset, int standardOffset) {
iMillis = millis;
iNameKey = nameKey;
iWallOffset = wallOffset;
iStandardOffset = standardOffset;
}
public long getMillis() {
return iMillis;
}
public String getNameKey() {
return iNameKey;
}
public int getWallOffset() {
return iWallOffset;
}
public int getStandardOffset() {
return iStandardOffset;
}
public int getSaveMillis() {
return iWallOffset - iStandardOffset;
}
/**
* There must be a change in the millis, wall offsets or name keys.
*/
public boolean isTransitionFrom(Transition other) {
if (other == null) {
return true;
}
return iMillis > other.iMillis &&
(iWallOffset != other.iWallOffset ||
//iStandardOffset != other.iStandardOffset ||
!(iNameKey.equals(other.iNameKey)));
}
}
private static final class RuleSet {
private static final int YEAR_LIMIT;
static {
// Don't pre-calculate more than 100 years into the future. Almost
// all zones will stop pre-calculating far sooner anyhow. Either a
// simple DST cycle is detected or the last rule is a fixed
// offset. If a zone has a fixed offset set more than 100 years
// into the future, then it won't be observed.
long now = DateTimeUtils.currentTimeMillis();
YEAR_LIMIT = ISOChronology.getInstanceUTC().year().get(
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> // Overflowed.
end = instant;
} catch (ArithmeticException e) {
// Overflowed.
end = instant;
}
return (start > end) ? end : start;
}
public long previousTransition(long instant) {
// Increment in order to handle the case where instant is exactly at
// a transition.
instant++;
int standardOffset = iStandardOffset;
Recurrence startRecurrence = iStartRecurrence;
Recurrence endRecurrence = iEndRecurrence;
long start, end;
try {
start = startRecurrence.previous
(instant, standardOffset, endRecurrence.getSaveMillis());
if (instant < 0 && start > 0) {
// Overflowed.
start = instant;
}
} catch (IllegalArgumentException e) {
// Overflowed.
start = instant;
} catch (ArithmeticException e) {
// Overflowed.
start = instant;
}
try {
end = endRecurrence.previous
(instant, standardOffset, startRecurrence.getSaveMillis());
if (instant < 0 && end > 0) {
// Overflowed.
end = instant;
}
} catch (IllegalArgumentException e) {
// Overflowed.
end = instant;
} catch (ArithmeticException e) {
// Overflowed.
end = instant;
}
return ((start > end) ? start : end) - 1;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof DSTZone) {
DSTZone other = (DSTZone)obj;
return
getID().equals(other.getID()) &&
iStandardOffset == other.iStandardOffset &&
iStartRecurrence.equals(other.iStartRecurrence) &&
iEndRecurrence.equals(other.iEndRecurrence);
}
return false;
}
public void writeTo(DataOutput out) throws IOException {
writeMillis(out, iStandardOffset);
iStartRecurrence.writeTo(out);
iEndRecurrence.writeTo(out);
}
private Recurrence findMatchingRecurrence(long instant) {
int standardOffset = iStandardOffset;
Recurrence startRecurrence = iStartRecurrence;
Recurrence endRecurrence = iEndRecurrence;
long start, end;
try {
start = startRecurrence.next
(instant, standardOffset, endRecurrence.getSaveMillis());
} catch (IllegalArgumentException e) {
// Overflowed.
start = instant;
} catch (ArithmeticException e) {
// Overflowed.
start = instant;
}
try {
end = endRecurrence.next
(instant, standardOffset, startRecurrence.getSaveMillis());
} catch (IllegalArgumentException e) {
// Overflowed.
end = instant;
} catch (ArithmeticException e) {
// Overflowed.
end = instant;
}
return (start > end
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> key for
// summer and winter which messes everything up. Fix it here.
String[] zoneNameData = new String[5];
String[][] zoneStrings = new DateFormatSymbols(Locale.ENGLISH).getZoneStrings();
for (int j = 0; j < zoneStrings.length; j++) {
String[] set = zoneStrings[j];
if (set != null && set.length == 5 && id.equals(set[0])) {
zoneNameData = set;
}
}
Chronology chrono = ISOChronology.getInstanceUTC();
for (int i = 0; i < nameKeys.length - 1; i++) {
String curNameKey = nameKeys[i];
String nextNameKey = nameKeys[i + 1];
long curOffset = wallOffsets[i];
long nextOffset = wallOffsets[i + 1];
long curStdOffset = standardOffsets[i];
long nextStdOffset = standardOffsets[i + 1];
Period p = new Period(trans[i], trans[i + 1], PeriodType.yearMonthDay(), chrono);
if (curOffset != nextOffset &&
curStdOffset == nextStdOffset &&
curNameKey.equals(nextNameKey) &&
p.getYears() == 0 && p.getMonths() > 4 && p.getMonths() < 8 &&
curNameKey.equals(zoneNameData[2]) &&
curNameKey.equals(zoneNameData[4])) {
if (ZoneInfoCompiler.verbose()) {
System.out.println("Fixing duplicate name key - " + nextNameKey);
System.out.println(" - " + new DateTime(trans[i], chrono) +
" - " + new DateTime(trans[i + 1], chrono));
}
if (curOffset > nextOffset) {
nameKeys[i] = (curNameKey + "-Summer").intern();
} else if (curOffset < nextOffset) {
nameKeys[i + 1] = (nextNameKey + "-Summer").intern();
i++;
}
}
}
if (tailZone != null) {
if (tailZone.iStartRecurrence.getNameKey()
.equals(tailZone.iEndRecurrence.getNameKey())) {
if (ZoneInfoCompiler.verbose()) {
System.out.println("Fixing duplicate recurrent name key - " +
tailZone.iStartRecurrence.getNameKey());
}
if (tailZone.iStartRecurrence.getSaveMillis() > 0) {
tailZone = new DSTZone(
tailZone.getID(),
tailZone.iStandardOffset,
tailZone.iStartRecurrence.renameAppend("-Summer"),
tailZone.iEndRecurrence);
} else {
tailZone = new DSTZone(
tailZone.getID(),
tailZone.iStandardOffset,
tailZone.iStart
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>0) ? (i + 1) : ~i;
if (i < transitions.length) {
return transitions[i];
}
if (iTailZone == null) {
return instant;
}
long end = transitions[transitions.length - 1];
if (instant < end) {
instant = end;
}
return iTailZone.nextTransition(instant);
}
public long previousTransition(long instant) {
long[] transitions = iTransitions;
int i = Arrays.binarySearch(transitions, instant);
if (i >= 0) {
if (instant > Long.MIN_VALUE) {
return instant - 1;
}
return instant;
}
i = ~i;
if (i < transitions.length) {
if (i > 0) {
long prev = transitions[i - 1];
if (prev > Long.MIN_VALUE) {
return prev - 1;
}
}
return instant;
}
if (iTailZone != null) {
long prev = iTailZone.previousTransition(instant);
if (prev < instant) {
return prev;
}
}
long prev = transitions[i - 1];
if (prev > Long.MIN_VALUE) {
return prev - 1;
}
return instant;
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof PrecalculatedZone) {
PrecalculatedZone other = (PrecalculatedZone)obj;
return
getID().equals(other.getID()) &&
Arrays.equals(iTransitions, other.iTransitions) &&
Arrays.equals(iNameKeys, other.iNameKeys) &&
Arrays.equals(iWallOffsets, other.iWallOffsets) &&
Arrays.equals(iStandardOffsets, other.iStandardOffsets) &&
((iTailZone == null)
? (null == other.iTailZone)
: (iTailZone.equals(other.iTailZone)));
}
return false;
}
public void writeTo(DataOutput out) throws IOException {
int size = iTransitions.length;
// Create unique string pool.
Set<String> poolSet = new HashSet<String>();
for (int i=0; i<size; i++) {
poolSet.add(iNameKeys[i]);
}
int poolSize = poolSet.size();
if (poolSize > 65535) {
throw new UnsupportedOperationException("String pool is too large");
}
String[] pool = new String[poolSize];
Iterator<String> it = poolSet.iterator();
for (int i=0; it.hasNext(); i++) {
pool[i] = it.next();
}
// Write out the pool.
out.writeShort(poolSize);
for (int i=0; i<poolSize; i++) {
out.writeUTF(
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>pool[i]);
}
out.writeInt(size);
for (int i=0; i<size; i++) {
writeMillis(out, iTransitions[i]);
writeMillis(out, iWallOffsets[i]);
writeMillis(out, iStandardOffsets[i]);
// Find pool index and write it out.
String nameKey = iNameKeys[i];
for (int j=0; j<poolSize; j++) {
if (pool[j].equals(nameKey)) {
if (poolSize < 256) {
out.writeByte(j);
} else {
out.writeShort(j);
}
break;
}
}
}
out.writeBoolean(iTailZone != null);
if (iTailZone != null) {
iTailZone.writeTo(out);
}
}
public boolean isCachable() {
if (iTailZone != null) {
return true;
}
long[] transitions = iTransitions;
if (transitions.length <= 1) {
return false;
}
// Add up all the distances between transitions that are less than
// about two years.
double distances = 0;
int count = 0;
for (int i=1; i<transitions.length; i++) {
long diff = transitions[i] - transitions[i - 1];
if (diff < ((366L + 365) * 24 * 60 * 60 * 1000)) {
distances += (double)diff;
count++;
}
}
if (count > 0) {
double avg = distances / count;
avg /= 24 * 60 * 60 * 1000;
if (avg >= 25) {
// Only bother caching if average distance between
// transitions is at least 25 days. Why 25?
// CachedDateTimeZone is more efficient if the distance
// between transitions is large. With an average of 25, it
// will on average perform about 2 tests per cache
// hit. (49.7 / 25) is approximately 2.
return true;
}
}
return false;
}
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2011 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.base;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DateTimeZone;
import org.joda.time.ReadableDateTime;
import org.joda.time.format.DateTimeFormat;
/**
* AbstractDateTime provides the common behaviour for datetime classes.
* <p>
* This class should generally not be used directly by API users.
* The {@link ReadableDateTime} interface should be used when different
* kinds of date/time objects are to be referenced.
* <p>
* Whenever you want to implement <code>ReadableDateTime</code> you should
* extend this class.
* <p>
* AbstractDateTime subclasses may be mutable and not thread-safe.
*
* @author Brian S O'Neill
* @author Stephen Colebourne
* @since 1.0
*/
public abstract class AbstractDateTime
extends AbstractInstant
implements ReadableDateTime {
/**
* Constructor.
*/
protected AbstractDateTime() {
super();
}
//-----------------------------------------------------------------------
/**
* Get the value of one of the fields of a datetime.
* <p>
* This method uses the chronology of the datetime to obtain the value.
* It is essentially a generic way of calling one of the get methods.
*
* @param type a field type, usually obtained from DateTimeFieldType
* @return the value of that field
* @throws IllegalArgumentException if the field type is null
*/
public int get(DateTimeFieldType type) {
if (type == null) {
throw new IllegalArgumentException("The DateTimeFieldType must not be null");
}
return type.getField(getChronology()).get(getMillis());
}
//-----------------------------------------------------------------------
/**
* Get the era field value.
*
* @return the era
*/
public int getEra() {
return getChronology().era().get(getMillis());
}
/**
* Get the year of era field value.
*
* @return the year of era
*/
public int getCenturyOfEra() {
return getCh
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>ronology().centuryOfEra().get(getMillis());
}
/**
* Get the year of era field value.
*
* @return the year of era
*/
public int getYearOfEra() {
return getChronology().yearOfEra().get(getMillis());
}
/**
* Get the year of century field value.
*
* @return the year of century
*/
public int getYearOfCentury() {
return getChronology().yearOfCentury().get(getMillis());
}
/**
* Get the year field value.
*
* @return the year
*/
public int getYear() {
return getChronology().year().get(getMillis());
}
/**
* Get the weekyear field value.
* <p>
* The weekyear is the year that matches with the weekOfWeekyear field.
* In the standard ISO8601 week algorithm, the first week of the year
* is that in which at least 4 days are in the year. As a result of this
* definition, day 1 of the first week may be in the previous year.
* The weekyear allows you to query the effective year for that day.
*
* @return the year of a week based year
*/
public int getWeekyear() {
return getChronology().weekyear().get(getMillis());
}
/**
* Get the month of year field value.
*
* @return the month of year
*/
public int getMonthOfYear() {
return getChronology().monthOfYear().get(getMillis());
}
/**
* Get the week of weekyear field value.
* <p>
* This field is associated with the "weekyear" via {@link #getWeekyear()}.
* In the standard ISO8601 week algorithm, the first week of the year
* is that in which at least 4 days are in the year. As a result of this
* definition, day 1 of the first week may be in the previous year.
*
* @return the week of a week based year
*/
public int getWeekOfWeekyear() {
return getChronology().weekOfWeekyear().get(getMillis());
}
/**
* Get the day of year field value.
*
* @return the day of year
*/
public int getDayOfYear() {
return getChronology().dayOfYear().get(getMillis());
}
/**
* Get the day of month field value.
* <p>
* The values for the day of month are defined in {@link org.joda.time.DateTimeConstants}.
*
* @return the day of month
*/
public int getDayOfMonth() {
return getChronology().dayOfMonth().get(getMillis());
}
/**
* Get the day of week field value.
* <p>
* The values for the day of week are defined
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>UnitMillis() < DateTimeConstants.MILLIS_PER_HOUR * 12;
}
/**
* Restricted constructor
*
* @param base base chronology to wrap
* @param zone the time zone
*/
private ZonedChronology(Chronology base, DateTimeZone zone) {
super(base, zone);
}
public DateTimeZone getZone() {
return (DateTimeZone)getParam();
}
public Chronology withUTC() {
return getBase();
}
public Chronology withZone(DateTimeZone zone) {
if (zone == null) {
zone = DateTimeZone.getDefault();
}
if (zone == getParam()) {
return this;
}
if (zone == DateTimeZone.UTC) {
return getBase();
}
return new ZonedChronology(getBase(), zone);
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int millisOfDay)
throws IllegalArgumentException
{
return localToUTC(getBase().getDateTimeMillis
(year, monthOfYear, dayOfMonth, millisOfDay));
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
return localToUTC(getBase().getDateTimeMillis
(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond));
}
public long getDateTimeMillis(long instant,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
return localToUTC(getBase().getDateTimeMillis
(instant + getZone().getOffset(instant),
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond));
}
/**
* @param instant instant from 1970-01-01T00:00:00 local time
* @return instant from 1970-01-01T00:00:00Z
*/
private long localToUTC(long instant) {
DateTimeZone zone = getZone();
int offset = zone.getOffsetFromLocal(instant);
instant -= offset;
if (offset != zone.getOffset(instant)) {
throw new IllegalArgumentException
("Illegal instant due to time zone offset transition: " +
DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").print(new Instant(instant)));
}
return instant;
}
protected void assemble(Fields fields) {
// Keep a local cache of converted fields so as not to create redundant
// objects.
HashMap<Object, Object> converted = new HashMap<Object, Object>();
// Convert duration fields...
fields.eras = convertField(fields.eras, converted);
fields.centuries = convertField(fields.centuries, converted);
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> fields.years = convertField(fields.years, converted);
fields.months = convertField(fields.months, converted);
fields.weekyears = convertField(fields.weekyears, converted);
fields.weeks = convertField(fields.weeks, converted);
fields.days = convertField(fields.days, converted);
fields.halfdays = convertField(fields.halfdays, converted);
fields.hours = convertField(fields.hours, converted);
fields.minutes = convertField(fields.minutes, converted);
fields.seconds = convertField(fields.seconds, converted);
fields.millis = convertField(fields.millis, converted);
// Convert datetime fields...
fields.year = convertField(fields.year, converted);
fields.yearOfEra = convertField(fields.yearOfEra, converted);
fields.yearOfCentury = convertField(fields.yearOfCentury, converted);
fields.centuryOfEra = convertField(fields.centuryOfEra, converted);
fields.era = convertField(fields.era, converted);
fields.dayOfWeek = convertField(fields.dayOfWeek, converted);
fields.dayOfMonth = convertField(fields.dayOfMonth, converted);
fields.dayOfYear = convertField(fields.dayOfYear, converted);
fields.monthOfYear = convertField(fields.monthOfYear, converted);
fields.weekOfWeekyear = convertField(fields.weekOfWeekyear, converted);
fields.weekyear = convertField(fields.weekyear, converted);
fields.weekyearOfCentury = convertField(fields.weekyearOfCentury, converted);
fields.millisOfSecond = convertField(fields.millisOfSecond, converted);
fields.millisOfDay = convertField(fields.millisOfDay, converted);
fields.secondOfMinute = convertField(fields.secondOfMinute, converted);
fields.secondOfDay = convertField(fields.secondOfDay, converted);
fields.minuteOfHour = convertField(fields.minuteOfHour, converted);
fields.minuteOfDay = convertField(fields.minuteOfDay, converted);
fields.hourOfDay = convertField(fields.hourOfDay, converted);
fields.hourOfHalfday = convertField(fields.hourOfHalfday, converted);
fields.clockhourOfDay = convertField(fields.clockhourOfDay, converted);
fields.clockhourOfHalfday = convertField(fields.clockhourOfHalfday, converted);
fields.halfdayOfDay = convertField(fields.halfdayOfDay, converted);
}
private DurationField convertField(DurationField field, HashMap<Object, Object> converted) {
if (field == null || !field.isSupported()) {
return field;
}
if (converted.containsKey(field)) {
return (DurationField)converted.get(field);
}
ZonedDurationField zonedField = new ZonedDurationField(field, getZone());
converted.put
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(field, zonedField);
return zonedField;
}
private DateTimeField convertField(DateTimeField field, HashMap<Object, Object> converted) {
if (field == null || !field.isSupported()) {
return field;
}
if (converted.containsKey(field)) {
return (DateTimeField)converted.get(field);
}
ZonedDateTimeField zonedField =
new ZonedDateTimeField(field, getZone(),
convertField(field.getDurationField(), converted),
convertField(field.getRangeDurationField(), converted),
convertField(field.getLeapDurationField(), converted));
converted.put(field, zonedField);
return zonedField;
}
//-----------------------------------------------------------------------
/**
* A zoned chronology is only equal to a zoned chronology with the
* same base chronology and zone.
*
* @param obj the object to compare to
* @return true if equal
* @since 1.4
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof ZonedChronology == false) {
return false;
}
ZonedChronology chrono = (ZonedChronology) obj;
return
getBase().equals(chrono.getBase()) &&
getZone().equals(chrono.getZone());
}
/**
* A suitable hashcode for the chronology.
*
* @return the hashcode
* @since 1.4
*/
public int hashCode() {
return 326565 + getZone().hashCode() * 11 + getBase().hashCode() * 7;
}
/**
* A debugging string for the chronology.
*
* @return the debugging string
*/
public String toString() {
return "ZonedChronology[" + getBase() + ", " + getZone().getID() + ']';
}
//-----------------------------------------------------------------------
/*
* Because time durations are typically smaller than time zone offsets, the
* arithmetic methods subtract the original offset. This produces a more
* expected behavior when crossing time zone offset transitions. For dates,
* the new offset is subtracted off. This behavior, if applied to time
* fields, can nullify or reverse an add when crossing a transition.
*/
static class ZonedDurationField extends BaseDurationField {
private static final long serialVersionUID = -485345310999208286L;
final DurationField iField;
final boolean iTimeField;
final DateTimeZone iZone;
ZonedDurationField(DurationField field, DateTimeZone zone) {
super(field.getType());
if (!field.isSupported()) {
throw new IllegalArgumentException();
}
iField = field;
iTimeField = useTimeArithmetic(field);
iZone = zone;
}
public boolean isPrecise() {
return iTimeField ? i
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>Field.isPrecise() : iField.isPrecise() && this.iZone.isFixed();
}
public long getUnitMillis() {
return iField.getUnitMillis();
}
public int getValue(long duration, long instant) {
return iField.getValue(duration, addOffset(instant));
}
public long getValueAsLong(long duration, long instant) {
return iField.getValueAsLong(duration, addOffset(instant));
}
public long getMillis(int value, long instant) {
return iField.getMillis(value, addOffset(instant));
}
public long getMillis(long value, long instant) {
return iField.getMillis(value, addOffset(instant));
}
public long add(long instant, int value) {
int offset = getOffsetToAdd(instant);
instant = iField.add(instant + offset, value);
return instant - (iTimeField ? offset : getOffsetFromLocalToSubtract(instant));
}
public long add(long instant, long value) {
int offset = getOffsetToAdd(instant);
instant = iField.add(instant + offset, value);
return instant - (iTimeField ? offset : getOffsetFromLocalToSubtract(instant));
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
int offset = getOffsetToAdd(subtrahendInstant);
return iField.getDifference
(minuendInstant + (iTimeField ? offset : getOffsetToAdd(minuendInstant)),
subtrahendInstant + offset);
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
int offset = getOffsetToAdd(subtrahendInstant);
return iField.getDifferenceAsLong
(minuendInstant + (iTimeField ? offset : getOffsetToAdd(minuendInstant)),
subtrahendInstant + offset);
}
private int getOffsetToAdd(long instant) {
int offset = this.iZone.getOffset(instant);
long sum = instant + offset;
// If there is a sign change, but the two values have the same sign...
if ((instant ^ sum) < 0 && (instant ^ offset) >= 0) {
throw new ArithmeticException("Adding time zone offset caused overflow");
}
return offset;
}
private int getOffsetFromLocalToSubtract(long instant) {
int offset = this.iZone.getOffsetFromLocal(instant);
long diff = instant - offset;
// If there is a sign change, but the two values have different signs...
if ((instant ^ diff) < 0 && (instant ^ offset) < 0) {
throw new ArithmeticException("Subtracting time zone offset caused overflow");
}
return offset;
}
private long addOffset(long instant) {
return iZone.convertUTCToLocal(instant);
}
}
/**
* A
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2011 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.base;
import org.joda.time.Chronology;
import org.joda.time.DateTime;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DateTimeUtils;
import org.joda.time.DurationFieldType;
import org.joda.time.ReadableInstant;
import org.joda.time.ReadablePartial;
import org.joda.time.field.FieldUtils;
import org.joda.time.format.DateTimeFormatter;
/**
* AbstractPartial provides a standard base implementation of most methods
* in the ReadablePartial interface.
* <p>
* Calculations on are performed using a {@link Chronology}.
* This chronology is set to be in the UTC time zone for all calculations.
* <p>
* The methods on this class use {@link ReadablePartial#size()},
* {@link AbstractPartial#getField(int, Chronology)} and
* {@link ReadablePartial#getValue(int)} to calculate their results.
* Subclasses may have a better implementation.
* <p>
* AbstractPartial allows subclasses may be mutable and not thread-safe.
*
* @author Stephen Colebourne
* @since 1.0
*/
public abstract class AbstractPartial
implements ReadablePartial, Comparable<ReadablePartial> {
//-----------------------------------------------------------------------
/**
* Constructor.
*/
protected AbstractPartial() {
super();
}
//-----------------------------------------------------------------------
/**
* Gets the field for a specific index in the chronology specified.
* <p>
* This method must not use any instance variables.
*
* @param index the index to retrieve
* @param chrono the chronology to use
* @return the field
* @throws IndexOutOfBoundsException if the index is invalid
*/
protected abstract DateTimeField getField(int index, Chronology chrono);
//-----------------------------------------------------------------------
/**
* Gets the field type at the specifed index.
*
* @param index the index
* @return the field type
* @throws IndexOutOfBoundsException if the index is invalid
*/
public DateTimeFieldType getFieldType(int index) {
return getField(index
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>, getChronology()).getType();
}
/**
* Gets an array of the field types that this partial supports.
* <p>
* The fields are returned largest to smallest, for example Hour, Minute, Second.
*
* @return the fields supported in an array that may be altered, largest to smallest
*/
public DateTimeFieldType[] getFieldTypes() {
DateTimeFieldType[] result = new DateTimeFieldType[size()];
for (int i = 0; i < result.length; i++) {
result[i] = getFieldType(i);
}
return result;
}
/**
* Gets the field at the specifed index.
*
* @param index the index
* @return the field
* @throws IndexOutOfBoundsException if the index is invalid
*/
public DateTimeField getField(int index) {
return getField(index, getChronology());
}
/**
* Gets an array of the fields that this partial supports.
* <p>
* The fields are returned largest to smallest, for example Hour, Minute, Second.
*
* @return the fields supported in an array that may be altered, largest to smallest
*/
public DateTimeField[] getFields() {
DateTimeField[] result = new DateTimeField[size()];
for (int i = 0; i < result.length; i++) {
result[i] = getField(i);
}
return result;
}
/**
* Gets an array of the value of each of the fields that this partial supports.
* <p>
* The fields are returned largest to smallest, for example Hour, Minute, Second.
* Each value corresponds to the same array index as <code>getFields()</code>
*
* @return the current values of each field in an array that may be altered, largest to smallest
*/
public int[] getValues() {
int[] result = new int[size()];
for (int i = 0; i < result.length; i++) {
result[i] = getValue(i);
}
return result;
}
//-----------------------------------------------------------------------
/**
* Get the value of one of the fields of a datetime.
* <p>
* The field specified must be one of those that is supported by the partial.
*
* @param type a DateTimeFieldType instance that is supported by this partial
* @return the value of that field
* @throws IllegalArgumentException if the field is null or not supported
*/
public int get(DateTimeFieldType type) {
return getValue(indexOfSupported(type));
}
/**
* Checks whether the field specified is supported by this partial.
*
* @param type the type to check, may be null which returns false
* @return true if the field is supported
*/
public boolean isSupported(DateTimeFieldType type) {
return (indexOf(type) != -1);
}
/**
* Gets the index of the specified field, or -1 if the field is unsupported.
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
*
* @param type the type to check, may be null which returns -1
* @return the index of the field, -1 if unsupported
*/
public int indexOf(DateTimeFieldType type) {
for (int i = 0, isize = size(); i < isize; i++) {
if (getFieldType(i) == type) {
return i;
}
}
return -1;
}
/**
* Gets the index of the specified field, throwing an exception if the
* field is unsupported.
*
* @param type the type to check, not null
* @return the index of the field
* @throws IllegalArgumentException if the field is null or not supported
*/
protected int indexOfSupported(DateTimeFieldType type) {
int index = indexOf(type);
if (index == -1) {
throw new IllegalArgumentException("Field '" + type + "' is not supported");
}
return index;
}
/**
* Gets the index of the first fields to have the specified duration,
* or -1 if the field is unsupported.
*
* @param type the type to check, may be null which returns -1
* @return the index of the field, -1 if unsupported
*/
protected int indexOf(DurationFieldType type) {
for (int i = 0, isize = size(); i < isize; i++) {
if (getFieldType(i).getDurationType() == type) {
return i;
}
}
return -1;
}
/**
* Gets the index of the first fields to have the specified duration,
* throwing an exception if the field is unsupported.
*
* @param type the type to check, not null
* @return the index of the field
* @throws IllegalArgumentException if the field is null or not supported
*/
protected int indexOfSupported(DurationFieldType type) {
int index = indexOf(type);
if (index == -1) {
throw new IllegalArgumentException("Field '" + type + "' is not supported");
}
return index;
}
//-----------------------------------------------------------------------
/**
* Resolves this partial against another complete instant to create a new
* full instant. The combination is performed using the chronology of the
* specified instant.
* <p>
* For example, if this partial represents a time, then the result of this
* method will be the datetime from the specified base instant plus the
* time from this partial.
*
* @param baseInstant the instant that provides the missing fields, null means now
* @return the combined datetime
*/
public DateTime toDateTime(ReadableInstant baseInstant) {
Chronology chrono = DateTimeUtils.getInstantChronology(baseInstant);
long instantMillis = DateTimeUtils.getInstantMillis(baseInstant);
long resolved = chrono.set(this, instantMillis);
return new DateTime(resolved, chrono);
}
//-----------------------------------------------------------------------
/**
* Compares this ReadablePartial with another returning true if the chron
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>ology,
* field types and values are equal.
*
* @param partial an object to check against
* @return true if fields and values are equal
*/
public boolean equals(Object partial) {
if (this == partial) {
return true;
}
if (partial instanceof ReadablePartial == false) {
return false;
}
ReadablePartial other = (ReadablePartial) partial;
if (size() != other.size()) {
return false;
}
for (int i = 0, isize = size(); i < isize; i++) {
if (getValue(i) != other.getValue(i) || getFieldType(i) != other.getFieldType(i)) {
return false;
}
}
return FieldUtils.equals(getChronology(), other.getChronology());
}
/**
* Gets a hash code for the ReadablePartial that is compatible with the
* equals method.
*
* @return a suitable hash code
*/
public int hashCode() {
int total = 157;
for (int i = 0, isize = size(); i < isize; i++) {
total = 23 * total + getValue(i);
total = 23 * total + getFieldType(i).hashCode();
}
total += getChronology().hashCode();
return total;
}
//-----------------------------------------------------------------------
/**
* Compares this partial with another returning an integer
* indicating the order.
* <p>
* The fields are compared in order, from largest to smallest.
* The first field that is non-equal is used to determine the result.
* <p>
* The specified object must be a partial instance whose field types
* match those of this partial.
* <p>
* NOTE: Prior to v2.0, the {@code Comparable} interface was only implemented
* in this class and not in the {@code ReadablePartial} interface.
*
* @param other an object to check against
* @return negative if this is less, zero if equal, positive if greater
* @throws ClassCastException if the partial is the wrong class
* or if it has field types that don't match
* @throws NullPointerException if the partial is null
* @since 1.1
*/
public int compareTo(ReadablePartial other) {
if (this == other) {
return 0;
}
if (size() != other.size()) {
throw new ClassCastException("ReadablePartial objects must have matching field types");
}
for (int i = 0, isize = size(); i < isize; i++) {
if (getFieldType(i) != other.getFieldType(i)) {
throw new ClassCastException("ReadablePartial objects must have matching field types");
}
}
// fields are ordered largest first
for (int i = 0, isize = size(); i < isize; i++) {
if (getValue(
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>i) > other.getValue(i)) {
return 1;
}
if (getValue(i) < other.getValue(i)) {
return -1;
}
}
return 0;
}
/**
* Is this partial later than the specified partial.
* <p>
* The fields are compared in order, from largest to smallest.
* The first field that is non-equal is used to determine the result.
* <p>
* You may not pass null into this method. This is because you need
* a time zone to accurately determine the current date.
*
* @param partial a partial to check against, must not be null
* @return true if this date is after the date passed in
* @throws IllegalArgumentException if the specified partial is null
* @throws ClassCastException if the partial has field types that don't match
* @since 1.1
*/
public boolean isAfter(ReadablePartial partial) {
if (partial == null) {
throw new IllegalArgumentException("Partial cannot be null");
}
return compareTo(partial) > 0;
}
/**
* Is this partial earlier than the specified partial.
* <p>
* The fields are compared in order, from largest to smallest.
* The first field that is non-equal is used to determine the result.
* <p>
* You may not pass null into this method. This is because you need
* a time zone to accurately determine the current date.
*
* @param partial a partial to check against, must not be null
* @return true if this date is before the date passed in
* @throws IllegalArgumentException if the specified partial is null
* @throws ClassCastException if the partial has field types that don't match
* @since 1.1
*/
public boolean isBefore(ReadablePartial partial) {
if (partial == null) {
throw new IllegalArgumentException("Partial cannot be null");
}
return compareTo(partial) < 0;
}
/**
* Is this partial the same as the specified partial.
* <p>
* The fields are compared in order, from largest to smallest.
* If all fields are equal, the result is true.
* <p>
* You may not pass null into this method. This is because you need
* a time zone to accurately determine the current date.
*
* @param partial a partial to check against, must not be null
* @return true if this date is the same as the date passed in
* @throws IllegalArgumentException if the specified partial is null
* @throws ClassCastException if the partial has field types that don't match
* @since 1.1
*/
public boolean isEqual(ReadablePartial partial) {
if (partial == null) {
throw new IllegalArgumentException("Partial cannot be null");
}
return compareTo(partial) == 0;
}
//-----------------------------------------------------------------------
/**
* Uses the specified formatter to convert this partial to a String.
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.field.FieldUtils;
import org.joda.time.field.ImpreciseDateTimeField;
/**
* Provides time calculations for the week of the weekyear component of time.
*
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.1, refactored from GJWeekyearDateTimeField
*/
final class BasicWeekyearDateTimeField extends ImpreciseDateTimeField {
private static final long serialVersionUID = 6215066916806820644L;
private static final long WEEK_53 = (53L - 1) * DateTimeConstants.MILLIS_PER_WEEK;
private final BasicChronology iChronology;
/**
* Restricted constructor
*/
BasicWeekyearDateTimeField(BasicChronology chronology) {
super(DateTimeFieldType.weekyear(), chronology.getAverageMillisPerYear());
iChronology = chronology;
}
public boolean isLenient() {
return false;
}
/**
* Get the Year of a week based year component of the specified time instant.
*
* @see org.joda.time.DateTimeField#get
* @param instant the time instant in millis to query.
* @return the year extracted from the input.
*/
public int get(long instant) {
return iChronology.getWeekyear(instant);
}
/**
* Add the specified years to the specified time instant.
*
* @see org.joda.time.DateTimeField#add
* @param instant the time instant in millis to update.
* @param years the years to add (can be negative).
* @return the updated time instant.
*/
public long add(long instant, int years) {
if (years == 0) {
return instant;
}
return set(instant, get(instant) + years);
}
public long
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>269054;
/** The highest year that can be fully supported. */
private static final int MAX_YEAR = 292272992;
/** Singleton instance of a UTC JulianChronology */
private static final JulianChronology INSTANCE_UTC;
/** Cache of zone to chronology arrays */
private static final Map<DateTimeZone, JulianChronology[]> cCache = new HashMap<DateTimeZone, JulianChronology[]>();
static {
INSTANCE_UTC = getInstance(DateTimeZone.UTC);
}
static int adjustYearForSet(int year) {
if (year <= 0) {
if (year == 0) {
throw new IllegalFieldValueException
(DateTimeFieldType.year(), Integer.valueOf(year), null, null);
}
year++;
}
return year;
}
/**
* Gets an instance of the JulianChronology.
* The time zone of the returned instance is UTC.
*
* @return a singleton UTC instance of the chronology
*/
public static JulianChronology getInstanceUTC() {
return INSTANCE_UTC;
}
/**
* Gets an instance of the JulianChronology in the default time zone.
*
* @return a chronology in the default time zone
*/
public static JulianChronology getInstance() {
return getInstance(DateTimeZone.getDefault(), 4);
}
/**
* Gets an instance of the JulianChronology in the given time zone.
*
* @param zone the time zone to get the chronology in, null is default
* @return a chronology in the specified time zone
*/
public static JulianChronology getInstance(DateTimeZone zone) {
return getInstance(zone, 4);
}
/**
* Gets an instance of the JulianChronology in the given time zone.
*
* @param zone the time zone to get the chronology in, null is default
* @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4
* @return a chronology in the specified time zone
*/
public static JulianChronology getInstance(DateTimeZone zone, int minDaysInFirstWeek) {
if (zone == null) {
zone = DateTimeZone.getDefault();
}
JulianChronology chrono;
synchronized (cCache) {
JulianChronology[] chronos = cCache.get(zone);
if (chronos == null) {
chronos = new JulianChronology[7];
cCache.put(zone, chronos);
}
try {
chrono = chronos[minDaysInFirstWeek - 1];
} catch (ArrayIndexOutOfBoundsException e) {
throw new IllegalArgumentException
("Invalid min days in first week: " + minDaysInFirstWeek);
}
if (chrono == null) {
if (zone == DateTimeZone.UTC
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>) {
chrono = new JulianChronology(null, null, minDaysInFirstWeek);
} else {
chrono = getInstance(DateTimeZone.UTC, minDaysInFirstWeek);
chrono = new JulianChronology
(ZonedChronology.getInstance(chrono, zone), null, minDaysInFirstWeek);
}
chronos[minDaysInFirstWeek - 1] = chrono;
}
}
return chrono;
}
// Constructors and instance variables
//-----------------------------------------------------------------------
/**
* Restricted constructor
*/
JulianChronology(Chronology base, Object param, int minDaysInFirstWeek) {
super(base, param, minDaysInFirstWeek);
}
/**
* Serialization singleton
*/
private Object readResolve() {
Chronology base = getBase();
int minDays = getMinimumDaysInFirstWeek();
minDays = (minDays == 0 ? 4 : minDays); // handle rename of BaseGJChronology
return base == null ?
getInstance(DateTimeZone.UTC, minDays) :
getInstance(base.getZone(), minDays);
}
// Conversion
//-----------------------------------------------------------------------
/**
* Gets the Chronology in the UTC time zone.
*
* @return the chronology in UTC
*/
public Chronology withUTC() {
return INSTANCE_UTC;
}
/**
* Gets the Chronology in a specific time zone.
*
* @param zone the zone to get the chronology in, null is default
* @return the chronology
*/
public Chronology withZone(DateTimeZone zone) {
if (zone == null) {
zone = DateTimeZone.getDefault();
}
if (zone == getZone()) {
return this;
}
return getInstance(zone);
}
long getDateMidnightMillis(int year, int monthOfYear, int dayOfMonth)
throws IllegalArgumentException
{
return super.getDateMidnightMillis(adjustYearForSet(year), monthOfYear, dayOfMonth);
}
boolean isLeapYear(int year) {
return (year & 3) == 0;
}
long calculateFirstDayOfYearMillis(int year) {
// Java epoch is 1970-01-01 Gregorian which is 1969-12-19 Julian.
// Calculate relative to the nearest leap year and account for the
// difference later.
int relativeYear = year - 1968;
int leapYears;
if (relativeYear <= 0) {
// Add 3 before shifting right since /4 and >>2 behave differently
// on negative numbers.
leapYears = (relativeYear + 3) >> 2;
} else {
leapYears = relativeYear >> 2;
// For post 1968 an adjustment is needed as jan1st is before leap day
if (!isLeapYear(
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import java.util.Locale;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.field.PreciseDurationDateTimeField;
/**
* GJDayOfWeekDateTimeField provides time calculations for the
* day of the week component of time.
*
* @since 1.0
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
*/
final class GJDayOfWeekDateTimeField extends PreciseDurationDateTimeField {
/** Serialization version */
private static final long serialVersionUID = -3857947176719041436L;
private final BasicChronology iChronology;
/**
* Restricted constructor.
*/
GJDayOfWeekDateTimeField(BasicChronology chronology, DurationField days) {
super(DateTimeFieldType.dayOfWeek(), days);
iChronology = chronology;
}
/**
* Get the value of the specified time instant.
*
* @param instant the time instant in millis to query
* @return the day of the week extracted from the input
*/
public int get(long instant) {
return iChronology.getDayOfWeek(instant);
}
/**
* Get the textual value of the specified time instant.
*
* @param fieldValue the field value to query
* @param locale the locale to use
* @return the day of the week, such as 'Monday'
*/
public String getAsText(int fieldValue, Locale locale) {
return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToText(fieldValue);
}
/**
* Get the abbreviated textual value of the specified time instant.
*
* @param fieldValue the field value to query
* @param locale the locale to use
* @return the day of the week, such as 'Mon'
*/
public String getAsShortText(int fieldValue, Locale locale) {
return GJLocaleSymbols.forLocale(locale).dayOfWeekValueToShort
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>Utils.getChronology(chronology));
}
//-----------------------------------------------------------------------
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the default time zone.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @since 2.0
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour) {
super(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, 0, 0);
}
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the specified time zone.
* <p>
* If the specified time zone is null, the default zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param zone the time zone, null means default time zone
* @since 2.0
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
DateTimeZone zone) {
super(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, 0, 0, zone);
}
/**
* Constructs an instance from datetime field values
* using the specified chronology.
* <p>
* If the chronology is null, <code>ISOChronology</code>
* in the default time zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param chronology the chronology, null means ISOChronology in default zone
* @since 2.0
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
Chronology chronology) {
super(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, 0, 0, chronology);
}
//-----------------------------------------------------------------------
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the default time zone.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @since 2.0
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute) {
super(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, 0);
}
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the specified time zone.
* <p>
* If the specified time zone is null, the default zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param zone the time zone, null means default time zone
* @since 2.0
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
DateTimeZone zone) {
super(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, 0, zone);
}
/**
* Constructs an instance from datetime field values
* using the specified chronology.
* <p>
* If the chronology is null, <code>ISOChronology</code>
* in the default time zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param chronology the chronology, null means ISOChronology in default zone
* @since 2.0
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
Chronology chronology) {
super(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, 0, chronology);
}
//-----------------------------------------------------------------------
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the default time zone.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
*
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> @param secondOfMinute the second of the minute
* @param millisOfSecond the millisecond of the second
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond) {
super(year, monthOfYear, dayOfMonth, hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the specified time zone.
* <p>
* If the specified time zone is null, the default zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param millisOfSecond the millisecond of the second
* @param zone the time zone, null means default time zone
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond,
DateTimeZone zone) {
super(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond, zone);
}
/**
* Constructs an instance from datetime field values
* using the specified chronology.
* <p>
* If the chronology is null, <code>ISOChronology</code>
* in the default time zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param millisOfSecond the millisecond of the second
* @param chronology the chronology, null means ISOChronology in default zone
*/
public DateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond,
Chronology chronology) {
super(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond, chronology);
}
//-----------------------------------------------------------------------
/**
* Get this object as a DateTime by returning <code>this</code>.
*
* @return <code>this</code>
*/
public DateTime toDateTime() {
return this;
}
/**
* Get this object as a DateTime using ISOChronology in the default zone,
* returning <code>this</
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>Millis = getZone().adjustOffset(getMillis(), false);
return withMillis(newMillis);
}
/**
* Returns a copy of this ZonedDateTime changing the zone offset to the later
* of the two valid offsets at a local time-line overlap.
* <p>
* This method only has any effect when the local time-line overlaps, such as at
* an autumn daylight savings cutover. In this scenario, there are two valid offsets
* for the local date-time. Calling this method will return a date-time with the
* later of the two selected.
* <p>
* If this method is called when it is not an overlap, this is returned.
* <p>
* This instance is immutable and unaffected by this method call.
*
* @return a copy of this datetime with the latest valid offset for the local datetime
*/
public DateTime withLaterOffsetAtOverlap() {
long newMillis = getZone().adjustOffset(getMillis(), true);
return withMillis(newMillis);
}
//-----------------------------------------------------------------------
/**
* Returns a copy of this datetime with the specified date, retaining the time fields.
* <p>
* If the date is already the date passed in, then <code>this</code> is returned.
* <p>
* To set a single field use the properties, for example:
* <pre>
* DateTime set = monthOfYear().setCopy(6);
* </pre>
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param year the new year value
* @param monthOfYear the new monthOfYear value
* @param dayOfMonth the new dayOfMonth value
* @return a copy of this datetime with a different date
* @throws IllegalArgumentException if any value if invalid
*/
public DateTime withDate(int year, int monthOfYear, int dayOfMonth) {
Chronology chrono = getChronology();
long instant = getMillis();
instant = chrono.year().set(instant, year);
instant = chrono.monthOfYear().set(instant, monthOfYear);
instant = chrono.dayOfMonth().set(instant, dayOfMonth);
return withMillis(instant);
}
/**
* Returns a copy of this datetime with the specified time, retaining the date fields.
* <p>
* If the time is already the time passed in, then <code>this</code> is returned.
* <p>
* To set a single field use the properties, for example:
* <pre>
* DateTime set = dt.hourOfDay().setCopy(6);
* </pre>
* <p>
* This instance is immutable and unaffected by this method call.
*
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param millisOfSecond the milli
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> </pre>
*
* @param fieldType the field type to set, not null
* @param value the value to set
* @return a copy of this datetime with the field set
* @throws IllegalArgumentException if the value is null or invalid
*/
public DateTime withField(DateTimeFieldType fieldType, int value) {
if (fieldType == null) {
throw new IllegalArgumentException("Field must not be null");
}
long instant = fieldType.getField(getChronology()).set(getMillis(), value);
return withMillis(instant);
}
/**
* Returns a copy of this datetime with the value of the specified field increased.
* <p>
* If the addition is zero or the field is null, then <code>this</code> is returned.
* <p>
* These three lines are equivalent:
* <pre>
* DateTime added = dt.withFieldAdded(DurationFieldType.years(), 6);
* DateTime added = dt.plusYears(6);
* DateTime added = dt.plus(Period.years(6));
* </pre>
*
* @param fieldType the field type to add to, not null
* @param amount the amount to add
* @return a copy of this datetime with the field updated
* @throws IllegalArgumentException if the value is null or invalid
* @throws ArithmeticException if the new datetime exceeds the capacity of a long
*/
public DateTime withFieldAdded(DurationFieldType fieldType, int amount) {
if (fieldType == null) {
throw new IllegalArgumentException("Field must not be null");
}
if (amount == 0) {
return this;
}
long instant = fieldType.getField(getChronology()).add(getMillis(), amount);
return withMillis(instant);
}
//-----------------------------------------------------------------------
/**
* Returns a copy of this datetime with the specified duration added.
* <p>
* If the addition is zero, then <code>this</code> is returned.
*
* @param durationToAdd the duration to add to this one
* @param scalar the amount of times to add, such as -1 to subtract once
* @return a copy of this datetime with the duration added
* @throws ArithmeticException if the new datetime exceeds the capacity of a long
*/
public DateTime withDurationAdded(long durationToAdd, int scalar) {
if (durationToAdd == 0 || scalar == 0) {
return this;
}
long instant = getChronology().add(getMillis(), durationToAdd, scalar);
return withMillis(instant);
}
/**
* Returns a copy of this datetime with the specified duration added.
* <p>
* If the addition is zero, then <code>this</code> is returned.
*
* @param durationToAdd the duration to add to this one, null means zero
* @param scalar the amount of times to add, such as -1 to subtract once
* @return a copy of this datetime with the duration added
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
* @param minutes the amount of minutes to subtract, may be negative
* @return the new datetime minus the increased minutes
* @since 1.1
*/
public DateTime minusMinutes(int minutes) {
if (minutes == 0) {
return this;
}
long instant = getChronology().minutes().subtract(getMillis(), minutes);
return withMillis(instant);
}
/**
* Returns a copy of this datetime minus the specified number of seconds.
* <p>
* The calculation will subtract a duration equivalent to the number of
* seconds expressed in milliseconds.
* <p>
* The following three lines are identical in effect:
* <pre>
* DateTime subtracted = dt.minusSeconds(6);
* DateTime subtracted = dt.minus(Period.seconds(6));
* DateTime subtracted = dt.withFieldAdded(DurationFieldType.seconds(), -6);
* </pre>
* <p>
* This datetime instance is immutable and unaffected by this method call.
*
* @param seconds the amount of seconds to subtract, may be negative
* @return the new datetime minus the increased seconds
* @since 1.1
*/
public DateTime minusSeconds(int seconds) {
if (seconds == 0) {
return this;
}
long instant = getChronology().seconds().subtract(getMillis(), seconds);
return withMillis(instant);
}
/**
* Returns a copy of this datetime minus the specified number of millis.
* <p>
* The calculation will subtract a duration equivalent to the number of
* milliseconds.
* <p>
* The following three lines are identical in effect:
* <pre>
* DateTime subtracted = dt.minusMillis(6);
* DateTime subtracted = dt.minus(Period.millis(6));
* DateTime subtracted = dt.withFieldAdded(DurationFieldType.millis(), -6);
* </pre>
* <p>
* This datetime instance is immutable and unaffected by this method call.
*
* @param millis the amount of millis to subtract, may be negative
* @return the new datetime minus the increased millis
* @since 1.1
*/
public DateTime minusMillis(int millis) {
if (millis == 0) {
return this;
}
long instant = getChronology().millis().subtract(getMillis(), millis);
return withMillis(instant);
}
//-----------------------------------------------------------------------
/**
* Gets the property object for the specified type, which contains many useful methods.
*
* @param type the field type to get the chronology for
* @return the property object
* @throws IllegalArgumentException if the field is null or unsupported
*/
public Property property(DateTimeFieldType type) {
if (type == null) {
throw new IllegalArgumentException("The DateTimeFieldType must not be null");
}
DateTimeField field = type.getField(getChronology());
if (field.
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> at least 4 days are in the year. As a result of this
* definition, day 1 of the first week may be in the previous year.
* The weekyear allows you to query the effective year for that day.
* <p>
* DateTime is immutable, so there are no set methods.
* Instead, this method returns a new instance with the value of
* weekyear changed.
*
* @param weekyear the weekyear to set
* @return a copy of this object with the field set
* @throws IllegalArgumentException if the value is invalid
* @since 1.3
*/
public DateTime withWeekyear(int weekyear) {
return withMillis(getChronology().weekyear().set(getMillis(), weekyear));
}
/**
* Returns a copy of this datetime with the month of year field updated.
* <p>
* DateTime is immutable, so there are no set methods.
* Instead, this method returns a new instance with the value of
* month of year changed.
*
* @param monthOfYear the month of year to set
* @return a copy of this object with the field set
* @throws IllegalArgumentException if the value is invalid
* @since 1.3
*/
public DateTime withMonthOfYear(int monthOfYear) {
return withMillis(getChronology().monthOfYear().set(getMillis(), monthOfYear));
}
/**
* Returns a copy of this datetime with the week of weekyear field updated.
* <p>
* This field is associated with the "weekyear" via {@link #withWeekyear(int)}.
* In the standard ISO8601 week algorithm, the first week of the year
* is that in which at least 4 days are in the year. As a result of this
* definition, day 1 of the first week may be in the previous year.
* <p>
* DateTime is immutable, so there are no set methods.
* Instead, this method returns a new instance with the value of
* week of weekyear changed.
*
* @param weekOfWeekyear the week of weekyear to set
* @return a copy of this object with the field set
* @throws IllegalArgumentException if the value is invalid
* @since 1.3
*/
public DateTime withWeekOfWeekyear(int weekOfWeekyear) {
return withMillis(getChronology().weekOfWeekyear().set(getMillis(), weekOfWeekyear));
}
/**
* Returns a copy of this datetime with the day of year field updated.
* <p>
* DateTime is immutable, so there are no set methods.
* Instead, this method returns a new instance with the value of
* day of year changed.
*
* @param dayOfYear the day of year to set
* @return a copy of this object with the field set
* @throws IllegalArgumentException if the value is invalid
* @since 1.3
*/
public DateTime withDayOfYear(int
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> week based year property
*/
public Property weekyear() {
return new Property(this, getChronology().weekyear());
}
/**
* Get the month of year property which provides access to advanced functionality.
*
* @return the month of year property
*/
public Property monthOfYear() {
return new Property(this, getChronology().monthOfYear());
}
/**
* Get the week of a week based year property which provides access to advanced functionality.
*
* @return the week of a week based year property
*/
public Property weekOfWeekyear() {
return new Property(this, getChronology().weekOfWeekyear());
}
/**
* Get the day of year property which provides access to advanced functionality.
*
* @return the day of year property
*/
public Property dayOfYear() {
return new Property(this, getChronology().dayOfYear());
}
/**
* Get the day of month property which provides access to advanced functionality.
*
* @return the day of month property
*/
public Property dayOfMonth() {
return new Property(this, getChronology().dayOfMonth());
}
/**
* Get the day of week property which provides access to advanced functionality.
*
* @return the day of week property
*/
public Property dayOfWeek() {
return new Property(this, getChronology().dayOfWeek());
}
// Time properties
//-----------------------------------------------------------------------
/**
* Get the hour of day field property which provides access to advanced functionality.
*
* @return the hour of day property
*/
public Property hourOfDay() {
return new Property(this, getChronology().hourOfDay());
}
/**
* Get the minute of day property which provides access to advanced functionality.
*
* @return the minute of day property
*/
public Property minuteOfDay() {
return new Property(this, getChronology().minuteOfDay());
}
/**
* Get the minute of hour field property which provides access to advanced functionality.
*
* @return the minute of hour property
*/
public Property minuteOfHour() {
return new Property(this, getChronology().minuteOfHour());
}
/**
* Get the second of day property which provides access to advanced functionality.
*
* @return the second of day property
*/
public Property secondOfDay() {
return new Property(this, getChronology().secondOfDay());
}
/**
* Get the second of minute field property which provides access to advanced functionality.
*
* @return the second of minute property
*/
public Property secondOfMinute() {
return new Property(this, getChronology().secondOfMinute());
}
/**
* Get the millis of day property which provides access to advanced functionality.
*
* @return the millis of day property
*/
public Property millisOfDay() {
return new Property(this, getChronology().millisOfDay());
}
/**
* Get the millis of second
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> property which provides access to advanced functionality.
*
* @return the millis of second property
*/
public Property millisOfSecond() {
return new Property(this, getChronology().millisOfSecond());
}
//-----------------------------------------------------------------------
/**
* DateTime.Property binds a DateTime to a DateTimeField allowing powerful
* datetime functionality to be easily accessed.
* <p>
* The simplest use of this class is as an alternative get method, here used to
* get the year '1972' (as an int) and the month 'December' (as a String).
* <pre>
* DateTime dt = new DateTime(1972, 12, 3, 0, 0, 0, 0);
* int year = dt.year().get();
* String monthStr = dt.month().getAsText();
* </pre>
* <p>
* Methods are also provided that allow date modification. These return new instances
* of DateTime - they do not modify the original. The example below yields two
* independent immutable date objects 20 years apart.
* <pre>
* DateTime dt = new DateTime(1972, 12, 3, 0, 0, 0, 0);
* DateTime dt20 = dt.year().addToCopy(20);
* </pre>
* Serious modification of dates (ie. more than just changing one or two fields)
* should use the {@link org.joda.time.MutableDateTime MutableDateTime} class.
* <p>
* DateTime.Propery itself is thread-safe and immutable, as well as the
* DateTime being operated on.
*
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.0
*/
public static final class Property extends AbstractReadableInstantFieldProperty {
/** Serialization version */
private static final long serialVersionUID = -6983323811635733510L;
/** The instant this property is working against */
private DateTime iInstant;
/** The field this property is working against */
private DateTimeField iField;
/**
* Constructor.
*
* @param instant the instant to set
* @param field the field to use
*/
Property(DateTime instant, DateTimeField field) {
super();
iInstant = instant;
iField = field;
}
/**
* Writes the property in a safe serialization format.
*/
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.writeObject(iInstant);
oos.writeObject(iField.getType());
}
/**
* Reads the property from a safe serialization format.
*/
private void readObject(ObjectInputStream oos) throws IOException, ClassNotFoundException {
iInstant = (DateTime) oos.readObject();
DateTimeFieldType type = (DateTimeFieldType) oos.readObject
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.ReadablePartial;
import org.joda.time.field.DecoratedDateTimeField;
import org.joda.time.field.FieldUtils;
/**
* This field is not publicy exposed by ISOChronology, but rather it is used to
* build the yearOfCentury and centuryOfEra fields. It merely drops the sign of
* the year.
*
* @author Brian S O'Neill
* @see GJYearOfEraDateTimeField
* @since 1.0
*/
class ISOYearOfEraDateTimeField extends DecoratedDateTimeField {
private static final long serialVersionUID = 7037524068969447317L;
/**
* Singleton instance
*/
static final DateTimeField INSTANCE = new ISOYearOfEraDateTimeField();
/**
* Restricted constructor.
*/
private ISOYearOfEraDateTimeField() {
super(GregorianChronology.getInstanceUTC().year(), DateTimeFieldType.yearOfEra());
}
public int get(long instant) {
int year = getWrappedField().get(instant);
return year < 0 ? -year : year;
}
public long add(long instant, int years) {
return getWrappedField().add(instant, years);
}
public long add(long instant, long years) {
return getWrappedField().add(instant, years);
}
public long addWrapField(long instant, int years) {
return getWrappedField().addWrapField(instant, years);
}
public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int years) {
return getWrappedField().addWrapField(instant, fieldIndex, values, years);
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
return getWrappedField().getDifference(minuendInstant, subtrahendInstant);
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
return getWrappedField
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
import org.joda.time.field.PreciseDurationDateTimeField;
/**
* Provides time calculations for the week of a week based year component of time.
*
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.1, refactored from GJWeekOfWeekyearDateTimeField
*/
final class BasicWeekOfWeekyearDateTimeField extends PreciseDurationDateTimeField {
private static final long serialVersionUID = -1587436826395135328L;
private final BasicChronology iChronology;
/**
* Restricted constructor
*/
BasicWeekOfWeekyearDateTimeField(BasicChronology chronology, DurationField weeks) {
super(DateTimeFieldType.weekOfWeekyear(), weeks);
iChronology = chronology;
}
/**
* Get the week of a week based year component of the specified time instant.
*
* @see org.joda.time.DateTimeField#get(long)
* @param instant the time instant in millis to query.
* @return the week of the year extracted from the input.
*/
public int get(long instant) {
return iChronology.getWeekOfWeekyear(instant);
}
public DurationField getRangeDurationField() {
return iChronology.weekyears();
}
// 1970-01-01 is day of week 4, Thursday. The rounding methods need to
// apply a corrective alignment since weeks begin on day of week 1, Monday.
public long roundFloor(long instant) {
return super.roundFloor(instant + 3 * DateTimeConstants.MILLIS_PER_DAY)
- 3 * DateTimeConstants.MILLIS_PER_DAY;
}
public long roundCeiling(long instant) {
return super.roundCeiling(instant + 3 * DateTimeConstants.MILLIS_PER_
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>DAY)
- 3 * DateTimeConstants.MILLIS_PER_DAY;
}
public long remainder(long instant) {
return super.remainder(instant + 3 * DateTimeConstants.MILLIS_PER_DAY);
}
public int getMinimumValue() {
return 1;
}
public int getMaximumValue() {
return 53;
}
public int getMaximumValue(long instant) {
int weekyear = iChronology.getWeekyear(instant);
return iChronology.getWeeksInYear(weekyear);
}
public int getMaximumValue(ReadablePartial partial) {
if (partial.isSupported(DateTimeFieldType.weekyear())) {
int weekyear = partial.get(DateTimeFieldType.weekyear());
return iChronology.getWeeksInYear(weekyear);
}
return 53;
}
public int getMaximumValue(ReadablePartial partial, int[] values) {
int size = partial.size();
for (int i = 0; i < size; i++) {
if (partial.getFieldType(i) == DateTimeFieldType.weekyear()) {
int weekyear = values[i];
return iChronology.getWeeksInYear(weekyear);
}
}
return 53;
}
protected int getMaximumValueForSet(long instant, int value) {
return value > 52 ? getMaximumValue(instant) : 52;
}
/**
* Serialization singleton
*/
private Object readResolve() {
return iChronology.weekOfWeekyear();
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
import org.joda.time.field.PreciseDurationDateTimeField;
/**
* Provides time calculations for the day of the year component of time.
*
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.1, refactored from GJDayOfYearDateTimeField
*/
final class BasicDayOfYearDateTimeField extends PreciseDurationDateTimeField {
private static final long serialVersionUID = -6821236822336841037L;
private final BasicChronology iChronology;
/**
* Restricted constructor
*/
BasicDayOfYearDateTimeField(BasicChronology chronology, DurationField days) {
super(DateTimeFieldType.dayOfYear(), days);
iChronology = chronology;
}
/**
* Get the day of the year component of the specified time instant.
*
* @param instant the time instant in millis to query.
* @return the day of the year extracted from the input.
*/
public int get(long instant) {
return iChronology.getDayOfYear(instant);
}
public DurationField getRangeDurationField() {
return iChronology.years();
}
public int getMinimumValue() {
return 1;
}
public int getMaximumValue() {
return iChronology.getDaysInYearMax();
}
public int getMaximumValue(long instant) {
int year = iChronology.getYear(instant);
return iChronology.getDaysInYear(year);
}
public int getMaximumValue(ReadablePartial partial) {
if (partial.isSupported(DateTimeFieldType.year())) {
int year = partial.get(DateTimeFieldType.year());
return iChronology.getDaysInYear(year);
}
return iChronology.getDaysInYearMax();
}
public int getMaximumValue(ReadablePartial partial, int[] values) {
int size
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> = partial.size();
for (int i = 0; i < size; i++) {
if (partial.getFieldType(i) == DateTimeFieldType.year()) {
int year = values[i];
return iChronology.getDaysInYear(year);
}
}
return iChronology.getDaysInYearMax();
}
protected int getMaximumValueForSet(long instant, int value) {
int maxLessOne = iChronology.getDaysInYearMax() - 1;
return (value > maxLessOne || value < 1) ? getMaximumValue(instant) : maxLessOne;
}
/**
* Serialization singleton
*/
private Object readResolve() {
return iChronology.dayOfYear();
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> to obtain the value.
* For example:
* <pre>
* DateTime dt = new DateTime();
* int year = dt.get(DateTimeFieldType.year());
* </pre>
*
* @param type a field type, usually obtained from DateTimeFieldType, not null
* @return the value of that field
* @throws IllegalArgumentException if the field type is null
*/
public int get(DateTimeFieldType type) {
if (type == null) {
throw new IllegalArgumentException("The DateTimeFieldType must not be null");
}
return type.getField(getChronology()).get(getMillis());
}
/**
* Checks if the field type specified is supported by this instant and chronology.
* This can be used to avoid exceptions in {@link #get(DateTimeFieldType)}.
*
* @param type a field type, usually obtained from DateTimeFieldType
* @return true if the field type is supported
*/
public boolean isSupported(DateTimeFieldType type) {
if (type == null) {
return false;
}
return type.getField(getChronology()).isSupported();
}
/**
* Get the value of one of the fields of a datetime.
* <p>
* This could be used to get a field using a different Chronology.
* For example:
* <pre>
* Instant dt = new Instant();
* int gjYear = dt.get(Chronology.getCoptic().year());
* </pre>
*
* @param field the DateTimeField to use, not null
* @return the value
* @throws IllegalArgumentException if the field is null
*/
public int get(DateTimeField field) {
if (field == null) {
throw new IllegalArgumentException("The DateTimeField must not be null");
}
return field.get(getMillis());
}
//-----------------------------------------------------------------------
/**
* Get this object as an Instant.
*
* @return an Instant using the same millis
*/
public Instant toInstant() {
return new Instant(getMillis());
}
/**
* Get this object as a DateTime in the same zone.
*
* @return a DateTime using the same millis
*/
public DateTime toDateTime() {
return new DateTime(getMillis(), getZone());
}
/**
* Get this object as a DateTime using ISOChronology in the same zone.
*
* @return a DateTime using the same millis with ISOChronology
*/
public DateTime toDateTimeISO() {
return new DateTime(getMillis(), ISOChronology.getInstance(getZone()));
}
/**
* Get this object as a DateTime using the same chronology but a different zone.
*
* @param zone time zone to apply, or default if null
* @return a DateTime using the same millis
*/
public DateTime toDateTime(DateTimeZone zone) {
Chronology chrono = DateTimeUtils.getChronology(getChronology());
chrono = chrono.withZone(zone);
return
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>>
* See {@link #isEqual(ReadableInstant)} for an equals method that
* ignores the Chronology and time zone.
* <p>
* All ReadableInstant instances are accepted.
*
* @param readableInstant a readable instant to check against
* @return true if millisecond and chronology are equal, false if
* not or the instant is null or of an incorrect type
*/
public boolean equals(Object readableInstant) {
// must be to fulfil ReadableInstant contract
if (this == readableInstant) {
return true;
}
if (readableInstant instanceof ReadableInstant == false) {
return false;
}
ReadableInstant otherInstant = (ReadableInstant) readableInstant;
return
getMillis() == otherInstant.getMillis() &&
FieldUtils.equals(getChronology(), otherInstant.getChronology());
}
/**
* Gets a hash code for the instant as defined in <code>ReadableInstant</code>.
*
* @return a suitable hash code
*/
public int hashCode() {
// must be to fulfil ReadableInstant contract
return
((int) (getMillis() ^ (getMillis() >>> 32))) +
(getChronology().hashCode());
}
/**
* Compares this object with the specified object for ascending
* millisecond instant order. This ordering is inconsistent with
* equals, as it ignores the Chronology.
* <p>
* All ReadableInstant instances are accepted.
*
* @param other a readable instant to check against
* @return negative value if this is less, 0 if equal, or positive value if greater
* @throws NullPointerException if the object is null
* @throws ClassCastException if the object type is not supported
*/
public int compareTo(ReadableInstant other) {
if (this == other) {
return 0;
}
long otherMillis = other.getMillis();
long thisMillis = getMillis();
// cannot do (thisMillis - otherMillis) as can overflow
if (thisMillis == otherMillis) {
return 0;
}
if (thisMillis < otherMillis) {
return -1;
} else {
return 1;
}
}
//-----------------------------------------------------------------------
/**
* Is this instant after the millisecond instant passed in
* comparing solely by millisecond.
*
* @param instant a millisecond instant to check against
* @return true if this instant is after the instant passed in
*/
public boolean isAfter(long instant) {
return (getMillis() > instant);
}
/**
* Is this instant after the current instant
* comparing solely by millisecond.
*
* @return true if this instant is after the current instant
*/
public boolean isAfterNow() {
return isAfter(DateTimeUtils.currentTimeMillis());
}
/**
* Is this instant after the instant passed in
* comparing solely by millisecond.
*
* @
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2011 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.tz;
import java.text.DateFormatSymbols;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import org.joda.time.DateTimeUtils;
/**
* The default name provider acquires localized names from
* {@link DateFormatSymbols java.text.DateFormatSymbols}.
* <p>
* DefaultNameProvider is thread-safe and immutable.
*
* @author Brian S O'Neill
* @since 1.0
*/
@SuppressWarnings("unchecked")
public class DefaultNameProvider implements NameProvider {
// locale -> (id -> (nameKey -> [shortName, name]))
private HashMap<Locale, Map<String, Map<String, Object>>> iByLocaleCache = createCache();
public DefaultNameProvider() {
}
public String getShortName(Locale locale, String id, String nameKey) {
String[] nameSet = getNameSet(locale, id, nameKey);
return nameSet == null ? null : nameSet[0];
}
public String getName(Locale locale, String id, String nameKey) {
String[] nameSet = getNameSet(locale, id, nameKey);
return nameSet == null ? null : nameSet[1];
}
private synchronized String[] getNameSet(Locale locale, String id, String nameKey) {
if (locale == null || id == null || nameKey == null) {
return null;
}
Map<String, Map<String, Object>> byIdCache = iByLocaleCache.get(locale);
if (byIdCache == null) {
iByLocaleCache.put(locale, byIdCache = createCache());
}
Map<String, Object> byNameKeyCache = byIdCache.get(id);
if (byNameKeyCache == null) {
byIdCache.put(id, byNameKeyCache = createCache());
String[][] zoneStringsEn = DateTimeUtils.getDateFormatSymbols(Locale.ENGLISH).getZoneStrings();
String[] setEn = null;
for (String[] strings : zoneStringsEn) {
if (strings != null && strings.length == 5 && id.equals(strings[0
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>])) {
setEn = strings;
break;
}
}
String[][] zoneStringsLoc = DateTimeUtils.getDateFormatSymbols(locale).getZoneStrings();
String[] setLoc = null;
for (String[] strings : zoneStringsLoc) {
if (strings != null && strings.length == 5 && id.equals(strings[0])) {
setLoc = strings;
break;
}
}
if (setEn != null && setLoc != null) {
byNameKeyCache.put(setEn[2], new String[] {setLoc[2], setLoc[1]});
// need to handle case where summer and winter have the same
// abbreviation, such as EST in Australia [1716305]
// we handle this by appending "-Summer", cf ZoneInfoCompiler
if (setEn[2].equals(setEn[4])) {
byNameKeyCache.put(setEn[4] + "-Summer", new String[] {setLoc[4], setLoc[3]});
} else {
byNameKeyCache.put(setEn[4], new String[] {setLoc[4], setLoc[3]});
}
}
}
return (String[]) byNameKeyCache.get(nameKey);
}
private HashMap createCache() {
return new HashMap(7);
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
/**
* Divides a DateTimeField such that the retrieved values are reduced by a
* fixed divisor. The field's unit duration is scaled accordingly, but the
* range duration is unchanged.
* <p>
* DividedDateTimeField is thread-safe and immutable.
*
* @see RemainderDateTimeField
*
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.0
*/
public class DividedDateTimeField extends DecoratedDateTimeField {
private static final long serialVersionUID = 8318475124230605365L;
// Shared with RemainderDateTimeField.
final int iDivisor;
final DurationField iDurationField;
private final int iMin;
private final int iMax;
/**
* Constructor.
*
* @param field the field to wrap, like "year()".
* @param type the field type this field will actually use
* @param divisor divisor, such as 100 years in a century
* @throws IllegalArgumentException if divisor is less than two
*/
public DividedDateTimeField(DateTimeField field,
DateTimeFieldType type, int divisor) {
super(field, type);
if (divisor < 2) {
throw new IllegalArgumentException("The divisor must be at least 2");
}
DurationField unitField = field.getDurationField();
if (unitField == null) {
iDurationField = null;
} else {
iDurationField = new ScaledDurationField(
unitField, type.getDurationType(), divisor);
}
iDivisor = divisor;
int i = field.getMinimumValue();
int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1);
int j = field.getMaximumValue();
int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1);
iMin = min;
iMax = max;
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
}
/**
* Construct a DividedDateTimeField that compliments the given
* RemainderDateTimeField.
*
* @param remainderField complimentary remainder field, like "yearOfCentury()".
* @param type the field type this field will actually use
*/
public DividedDateTimeField(RemainderDateTimeField remainderField, DateTimeFieldType type) {
super(remainderField.getWrappedField(), type);
int divisor = iDivisor = remainderField.iDivisor;
iDurationField = remainderField.iRangeField;
DateTimeField field = getWrappedField();
int i = field.getMinimumValue();
int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1);
int j = field.getMaximumValue();
int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1);
iMin = min;
iMax = max;
}
/**
* Get the amount of scaled units from the specified time instant.
*
* @param instant the time instant in millis to query.
* @return the amount of scaled units extracted from the input.
*/
public int get(long instant) {
int value = getWrappedField().get(instant);
if (value >= 0) {
return value / iDivisor;
} else {
return ((value + 1) / iDivisor) - 1;
}
}
/**
* Add the specified amount of scaled units to the specified time
* instant. The amount added may be negative.
*
* @param instant the time instant in millis to update.
* @param amount the amount of scaled units to add (can be negative).
* @return the updated time instant.
*/
public long add(long instant, int amount) {
return getWrappedField().add(instant, amount * iDivisor);
}
/**
* Add the specified amount of scaled units to the specified time
* instant. The amount added may be negative.
*
* @param instant the time instant in millis to update.
* @param amount the amount of scaled units to add (can be negative).
* @return the updated time instant.
*/
public long add(long instant, long amount) {
return getWrappedField().add(instant, amount * iDivisor);
}
/**
* Add to the scaled component of the specified time instant,
* wrapping around within that component if necessary.
*
* @param instant the time instant in millis to update.
* @param amount the amount of scaled units to add (can be negative).
* @return the updated time instant.
*/
public long addWrapField(long instant, int amount) {
return set(instant, FieldUtils.getWrappedValue(get(instant), amount, iMin, iMax));
}
public int getDifference(long minuendInstant, long sub
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
/**
* Precise datetime field, which has a precise unit duration field.
* <p>
* PreciseDurationDateTimeField is thread-safe and immutable, and its
* subclasses must be as well.
*
* @author Brian S O'Neill
* @since 1.0
*/
public abstract class PreciseDurationDateTimeField extends BaseDateTimeField {
private static final long serialVersionUID = 5004523158306266035L;
/** The fractional unit in millis */
final long iUnitMillis;
private final DurationField iUnitField;
/**
* Constructor.
*
* @param type the field type
* @param unit precise unit duration, like "days()".
* @throws IllegalArgumentException if duration field is imprecise
* @throws IllegalArgumentException if unit milliseconds is less than one
*/
public PreciseDurationDateTimeField(DateTimeFieldType type, DurationField unit) {
super(type);
if (!unit.isPrecise()) {
throw new IllegalArgumentException("Unit duration field must be precise");
}
iUnitMillis = unit.getUnitMillis();
if (iUnitMillis < 1) {
throw new IllegalArgumentException("The unit milliseconds must be at least 1");
}
iUnitField = unit;
}
/**
* Returns false by default.
*/
public boolean isLenient() {
return false;
}
/**
* Set the specified amount of units to the specified time instant.
*
* @param instant the milliseconds from 1970-01-01T00:00:00Z to set in
* @param value value of units to set.
* @return the updated time instant.
* @throws IllegalArgumentException if value is too large or too small.
*/
public long set(long instant, int value) {
FieldUtils.verifyValueBounds(this, value, getMinimumValue(),
getMaximumValueForSet(instant, value));
return instant + (value - get(instant)) * iUnitMillis;
}
/**
* This
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> rare
* cases have multiple transitions.
*/
private final DateTimeZone iZone;
private final Info[] iInfoCache = new Info[cInfoCacheMask + 1];
private CachedDateTimeZone(DateTimeZone zone) {
super(zone.getID());
iZone = zone;
}
/**
* Returns the DateTimeZone being wrapped.
*/
public DateTimeZone getUncachedZone() {
return iZone;
}
public String getNameKey(long instant) {
return getInfo(instant).getNameKey(instant);
}
public int getOffset(long instant) {
return getInfo(instant).getOffset(instant);
}
public int getStandardOffset(long instant) {
return getInfo(instant).getStandardOffset(instant);
}
public boolean isFixed() {
return iZone.isFixed();
}
public long nextTransition(long instant) {
return iZone.nextTransition(instant);
}
public long previousTransition(long instant) {
return iZone.previousTransition(instant);
}
public int hashCode() {
return iZone.hashCode();
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof CachedDateTimeZone) {
return iZone.equals(((CachedDateTimeZone)obj).iZone);
}
return false;
}
// Although accessed by multiple threads, this method doesn't need to be
// synchronized.
private Info getInfo(long millis) {
int period = (int)(millis >> 32);
Info[] cache = iInfoCache;
int index = period & cInfoCacheMask;
Info info = cache[index];
if (info == null || (int)((info.iPeriodStart >> 32)) != period) {
info = createInfo(millis);
cache[index] = info;
}
return info;
}
private Info createInfo(long millis) {
long periodStart = millis & (0xffffffffL << 32);
Info info = new Info(iZone, periodStart);
long end = periodStart | 0xffffffffL;
Info chain = info;
while (true) {
long next = iZone.nextTransition(periodStart);
if (next == periodStart || next > end) {
break;
}
periodStart = next;
chain = (chain.iNextInfo = new Info(iZone, periodStart));
}
return info;
}
private final static class Info {
// For first Info in chain, iPeriodStart's lower 32 bits are clear.
public final long iPeriodStart;
public final DateTimeZone iZoneRef;
Info iNextInfo;
private String iNameKey;
private int iOffset = Integer.MIN_VALUE;
private int iStandardOffset = Integer.MIN_VALUE;
Info(DateTimeZone zone, long periodStart) {
iPeriodStart = periodStart;
iZoneRef = zone;
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>getZone());
}
// Conversion
//-----------------------------------------------------------------------
/**
* Gets the Chronology in the UTC time zone.
*
* @return the chronology in UTC
*/
public Chronology withUTC() {
return INSTANCE_UTC;
}
/**
* Gets the Chronology in a specific time zone.
*
* @param zone the zone to get the chronology in, null is default
* @return the chronology
*/
public Chronology withZone(DateTimeZone zone) {
if (zone == null) {
zone = DateTimeZone.getDefault();
}
if (zone == getZone()) {
return this;
}
return getInstance(zone);
}
/**
* Checks if this chronology instance equals another.
*
* @param obj the object to compare to
* @return true if equal
* @since 1.6
*/
public boolean equals(Object obj) {
return super.equals(obj);
}
/**
* A suitable hash code for the chronology.
*
* @return the hash code
* @since 1.6
*/
public int hashCode() {
return "Buddhist".hashCode() * 11 + getZone().hashCode();
}
// Output
//-----------------------------------------------------------------------
/**
* Gets a debugging toString.
*
* @return a debugging string
*/
public String toString() {
String str = "BuddhistChronology";
DateTimeZone zone = getZone();
if (zone != null) {
str = str + '[' + zone.getID() + ']';
}
return str;
}
protected void assemble(Fields fields) {
if (getParam() == null) {
// julian chrono removed zero, but we need to put it back
DateTimeField field = fields.year;
fields.year = new OffsetDateTimeField(
new SkipUndoDateTimeField(this, field), BUDDHIST_OFFSET);
// one era, so yearOfEra is the same
field = fields.yearOfEra;
fields.yearOfEra = new DelegatedDateTimeField(
fields.year, DateTimeFieldType.yearOfEra());
// julian chrono removed zero, but we need to put it back
field = fields.weekyear;
fields.weekyear = new OffsetDateTimeField(
new SkipUndoDateTimeField(this, field), BUDDHIST_OFFSET);
field = new OffsetDateTimeField(fields.yearOfEra, 99);
fields.centuryOfEra = new DividedDateTimeField(
field, DateTimeFieldType.centuryOfEra(), 100);
field = new RemainderDateTimeField(
(DividedDateTimeField) fields.centuryOfEra);
fields.yearOfCentury = new OffsetDateTimeField(
field, DateTimeFieldType.yearOfCentury(), 1);
field = new RemainderDateTimeField(
fields.weekyear, DateTimeFieldType.weekyearOfCentury(), 100
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>);
fields.weekyearOfCentury = new OffsetDateTimeField(
field, DateTimeFieldType.weekyearOfCentury(), 1);
fields.era = ERA_FIELD;
}
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
/**
* Counterpart remainder datetime field to {@link DividedDateTimeField}. The
* field's unit duration is unchanged, but the range duration is scaled
* accordingly.
* <p>
* RemainderDateTimeField is thread-safe and immutable.
*
* @see DividedDateTimeField
*
* @author Brian S O'Neill
* @since 1.0
*/
public class RemainderDateTimeField extends DecoratedDateTimeField {
private static final long serialVersionUID = 5708241235177666790L;
// Shared with DividedDateTimeField.
final int iDivisor;
final DurationField iRangeField;
/**
* Constructor.
*
* @param field the field to wrap, like "year()".
* @param type the field type this field actually uses
* @param divisor divisor, such as 100 years in a century
* @throws IllegalArgumentException if divisor is less than two
*/
public RemainderDateTimeField(DateTimeField field,
DateTimeFieldType type, int divisor) {
super(field, type);
if (divisor < 2) {
throw new IllegalArgumentException("The divisor must be at least 2");
}
DurationField rangeField = field.getDurationField();
if (rangeField == null) {
iRangeField = null;
} else {
iRangeField = new ScaledDurationField(
rangeField, type.getRangeDurationType(), divisor);
}
iDivisor = divisor;
}
/**
* Construct a RemainderDateTimeField that compliments the given
* DividedDateTimeField.
*
* @param dividedField complimentary divided field, like "century()".
*/
public RemainderDateTimeField(DividedDateTimeField dividedField) {
this(dividedField, dividedField.getType());
}
/**
* Construct a RemainderDateTimeField that compliments the given
* DividedDateTimeField.
*
* @param dividedField complimentary divided field,
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> like "century()".
* @param type the field type this field actually uses
*/
public RemainderDateTimeField(DividedDateTimeField dividedField, DateTimeFieldType type) {
super(dividedField.getWrappedField(), type);
iDivisor = dividedField.iDivisor;
iRangeField = dividedField.iDurationField;
}
//-----------------------------------------------------------------------
/**
* Get the remainder from the specified time instant.
*
* @param instant the time instant in millis to query.
* @return the remainder extracted from the input.
*/
public int get(long instant) {
int value = getWrappedField().get(instant);
if (value >= 0) {
return value % iDivisor;
} else {
return (iDivisor - 1) + ((value + 1) % iDivisor);
}
}
/**
* Add the specified amount to the specified time instant, wrapping around
* within the remainder range if necessary. The amount added may be
* negative.
*
* @param instant the time instant in millis to update.
* @param amount the amount to add (can be negative).
* @return the updated time instant.
*/
public long addWrapField(long instant, int amount) {
return set(instant, FieldUtils.getWrappedValue(get(instant), amount, 0, iDivisor - 1));
}
/**
* Set the specified amount of remainder units to the specified time instant.
*
* @param instant the time instant in millis to update.
* @param value value of remainder units to set.
* @return the updated time instant.
* @throws IllegalArgumentException if value is too large or too small.
*/
public long set(long instant, int value) {
FieldUtils.verifyValueBounds(this, value, 0, iDivisor - 1);
int divided = getDivided(getWrappedField().get(instant));
return getWrappedField().set(instant, divided * iDivisor + value);
}
/**
* Returns a scaled version of the wrapped field's unit duration field.
*/
public DurationField getRangeDurationField() {
return iRangeField;
}
/**
* Get the minimum value for the field, which is always zero.
*
* @return the minimum value of zero.
*/
public int getMinimumValue() {
return 0;
}
/**
* Get the maximum value for the field, which is always one less than the
* divisor.
*
* @return the maximum value
*/
public int getMaximumValue() {
return iDivisor - 1;
}
public long roundFloor(long instant) {
return getWrappedField().roundFloor(instant);
}
public long roundCeiling(long instant) {
return getWrappedField().roundCeiling(instant);
}
public long roundHalfFloor(long instant) {
return getWrappedField().round
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.field.FieldUtils;
import org.joda.time.field.ImpreciseDateTimeField;
/**
* A year field suitable for many calendars.
*
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.1, refactored from GJYearDateTimeField
*/
class BasicYearDateTimeField extends ImpreciseDateTimeField {
/** Serialization version. */
private static final long serialVersionUID = -98628754872287L;
/** The underlying basic chronology. */
protected final BasicChronology iChronology;
/**
* Restricted constructor.
*
* @param chronology the chronology this field belogs to
*/
BasicYearDateTimeField(BasicChronology chronology) {
super(DateTimeFieldType.year(), chronology.getAverageMillisPerYear());
iChronology = chronology;
}
public boolean isLenient() {
return false;
}
public int get(long instant) {
return iChronology.getYear(instant);
}
public long add(long instant, int years) {
if (years == 0) {
return instant;
}
int thisYear = get(instant);
int newYear = FieldUtils.safeAdd(thisYear, years);
return set(instant, newYear);
}
public long add(long instant, long years) {
return add(instant, FieldUtils.safeToInt(years));
}
public long addWrapField(long instant, int years) {
if (years == 0) {
return instant;
}
// Return newly calculated millis value
int thisYear = iChronology.getYear(instant);
int wrappedYear = FieldUtils.getWrappedValue
(thisYear, years, iChronology.getMinYear(), iChronology.getMaxYear());
return set(instant, wrappedYear);
}
public long set(long instant, int year
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
/**
* <code>DecoratedDateTimeField</code> extends {@link BaseDateTimeField},
* implementing only the minimum required set of methods. These implemented
* methods delegate to a wrapped field.
* <p>
* This design allows new DateTimeField types to be defined that piggyback on
* top of another, inheriting all the safe method implementations from
* BaseDateTimeField. Should any method require pure delegation to the
* wrapped field, simply override and use the provided getWrappedField method.
* <p>
* DecoratedDateTimeField is thread-safe and immutable, and its subclasses must
* be as well.
*
* @author Brian S O'Neill
* @since 1.0
* @see DelegatedDateTimeField
*/
public abstract class DecoratedDateTimeField extends BaseDateTimeField {
/** Serialization version */
private static final long serialVersionUID = 203115783733757597L;
/** The DateTimeField being wrapped */
private final DateTimeField iField;
/**
* Constructor.
*
* @param field the field being decorated
* @param type allow type to be overridden
*/
protected DecoratedDateTimeField(DateTimeField field, DateTimeFieldType type) {
super(type);
if (field == null) {
throw new IllegalArgumentException("The field must not be null");
}
if (!field.isSupported()) {
throw new IllegalArgumentException("The field must be supported");
}
iField = field;
}
/**
* Gets the wrapped date time field.
*
* @return the wrapped DateTimeField
*/
public final DateTimeField getWrappedField() {
return iField;
}
public boolean isLenient() {
return iField.isLenient();
}
public int get(long instant) {
return iField.get(instant);
}
public long set(long instant, int value) {
return iField.set(instant, value);
}
public DurationField getDurationField() {
return iField.getDurationField();
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2009 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import java.io.Serializable;
import org.joda.time.DurationField;
import org.joda.time.DurationFieldType;
/**
* BaseDurationField provides the common behaviour for DurationField
* implementations.
* <p>
* This class should generally not be used directly by API users. The
* DurationField class should be used when different kinds of DurationField
* objects are to be referenced.
* <p>
* BaseDurationField is thread-safe and immutable, and its subclasses must
* be as well.
*
* @author Brian S O'Neill
* @see DecoratedDurationField
* @since 1.0
*/
public abstract class BaseDurationField extends DurationField implements Serializable {
/** Serialization lock. */
private static final long serialVersionUID = -2554245107589433218L;
/** A desriptive name for the field. */
private final DurationFieldType iType;
protected BaseDurationField(DurationFieldType type) {
super();
if (type == null) {
throw new IllegalArgumentException("The type must not be null");
}
iType = type;
}
public final DurationFieldType getType() {
return iType;
}
public final String getName() {
return iType.getName();
}
/**
* @return true always
*/
public final boolean isSupported() {
return true;
}
//------------------------------------------------------------------------
/**
* Get the value of this field from the milliseconds, which is approximate
* if this field is imprecise.
*
* @param duration the milliseconds to query, which may be negative
* @return the value of the field, in the units of the field, which may be
* negative
*/
public int getValue(long duration) {
return FieldUtils.safeToInt(getValueAsLong(duration));
}
/**
* Get the value of this field from the milliseconds, which is approximate
* if this field is imprecise.
*
* @param duration the milliseconds to query, which may be negative
* @return the value of the field, in the units of the field, which may be
* negative
*/
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
public long getValueAsLong(long duration) {
return duration / getUnitMillis();
}
/**
* Get the value of this field from the milliseconds relative to an
* instant.
*
* <p>If the milliseconds is positive, then the instant is treated as a
* "start instant". If negative, the instant is treated as an "end
* instant".
*
* <p>The default implementation returns
* <code>Utils.safeToInt(getAsLong(millisDuration, instant))</code>.
*
* @param duration the milliseconds to query, which may be negative
* @param instant the start instant to calculate relative to
* @return the value of the field, in the units of the field, which may be
* negative
*/
public int getValue(long duration, long instant) {
return FieldUtils.safeToInt(getValueAsLong(duration, instant));
}
/**
* Get the millisecond duration of this field from its value, which is
* approximate if this field is imprecise.
*
* @param value the value of the field, which may be negative
* @return the milliseconds that the field represents, which may be
* negative
*/
public long getMillis(int value) {
return value * getUnitMillis(); // safe
}
/**
* Get the millisecond duration of this field from its value, which is
* approximate if this field is imprecise.
*
* @param value the value of the field, which may be negative
* @return the milliseconds that the field represents, which may be
* negative
*/
public long getMillis(long value) {
return FieldUtils.safeMultiply(value, getUnitMillis());
}
// Calculation API
//------------------------------------------------------------------------
public int getDifference(long minuendInstant, long subtrahendInstant) {
return FieldUtils.safeToInt(getDifferenceAsLong(minuendInstant, subtrahendInstant));
}
//------------------------------------------------------------------------
public int compareTo(DurationField otherField) {
long otherMillis = otherField.getUnitMillis();
long thisMillis = getUnitMillis();
// cannot do (thisMillis - otherMillis) as can overflow
if (thisMillis == otherMillis) {
return 0;
}
if (thisMillis < otherMillis) {
return -1;
} else {
return 1;
}
}
/**
* Get a suitable debug string.
*
* @return debug string
*/
public String toString() {
return "DurationField[" + getName() + ']';
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>);
if (value <= iSkip) {
value--;
}
return value;
}
public long set(long millis, int value) {
FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
if (value <= iSkip) {
if (value == iSkip) {
throw new IllegalFieldValueException
(DateTimeFieldType.year(), Integer.valueOf(value), null, null);
}
value++;
}
return super.set(millis, value);
}
public int getMinimumValue() {
return iMinValue;
}
private Object readResolve() {
return getType().getField(iChronology);
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
iDefaultYear = defaultYear;
}
//-----------------------------------------------------------------------
/**
* Is this formatter capable of printing.
*
* @return true if this is a printer
*/
public boolean isPrinter() {
return (iPrinter != null);
}
/**
* Gets the internal printer object that performs the real printing work.
*
* @return the internal printer; is null if printing not supported
*/
public DateTimePrinter getPrinter() {
return iPrinter;
}
/**
* Is this formatter capable of parsing.
*
* @return true if this is a parser
*/
public boolean isParser() {
return (iParser != null);
}
/**
* Gets the internal parser object that performs the real parsing work.
*
* @return the internal parser; is null if parsing not supported
*/
public DateTimeParser getParser() {
return iParser;
}
//-----------------------------------------------------------------------
/**
* Returns a new formatter with a different locale that will be used
* for printing and parsing.
* <p>
* A DateTimeFormatter is immutable, so a new instance is returned,
* and the original is unaltered and still usable.
*
* @param locale the locale to use; if null, formatter uses default locale
* at invocation time
* @return the new formatter
*/
public DateTimeFormatter withLocale(Locale locale) {
if (locale == getLocale() || (locale != null && locale.equals(getLocale()))) {
return this;
}
return new DateTimeFormatter(iPrinter, iParser, locale,
iOffsetParsed, iChrono, iZone, iPivotYear, iDefaultYear);
}
/**
* Gets the locale that will be used for printing and parsing.
*
* @return the locale to use; if null, formatter uses default locale at
* invocation time
*/
public Locale getLocale() {
return iLocale;
}
//-----------------------------------------------------------------------
/**
* Returns a new formatter that will create a datetime with a time zone
* equal to that of the offset of the parsed string.
* <p>
* After calling this method, a string '2004-06-09T10:20:30-08:00' will
* create a datetime with a zone of -08:00 (a fixed zone, with no daylight
* savings rules). If the parsed string represents a local time (no zone
* offset) the parsed datetime will be in the default zone.
* <p>
* Calling this method sets the override zone to null.
* Calling the override zone method sets this flag off.
*
* @return the new formatter
*/
public DateTimeFormatter withOffsetParsed() {
if (iOffsetParsed == true) {
return this;
}
return new DateTimeFormatter(iPrinter, iParser, iLocale,
true, iChrono, null, iPivotYear, iDefaultYear);
}
/**
* Checks whether the offset from the
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>PivotYear == pivotYear || (iPivotYear != null && iPivotYear.equals(pivotYear))) {
return this;
}
return new DateTimeFormatter(iPrinter, iParser, iLocale,
iOffsetParsed, iChrono, iZone, pivotYear, iDefaultYear);
}
/**
* Returns a new formatter that will use the specified pivot year for two
* digit year parsing in preference to that stored in the parser.
* <p>
* This setting is useful for changing the pivot year of formats built
* using a pattern - {@link DateTimeFormat#forPattern(String)}.
* <p>
* When parsing, this pivot year is used.
* There is no effect when printing.
* <p>
* The pivot year enables a two digit year to be converted to a four
* digit year. The pivot represents the year in the middle of the
* supported range of years. Thus the full range of years that will
* be built is <code>(pivot - 50) .. (pivot + 49)</code>.
*
* <pre>
* pivot supported range 00 is 20 is 40 is 60 is 80 is
* ---------------------------------------------------------------
* 1950 1900..1999 1900 1920 1940 1960 1980
* 1975 1925..2024 2000 2020 1940 1960 1980
* 2000 1950..2049 2000 2020 2040 1960 1980
* 2025 1975..2074 2000 2020 2040 2060 1980
* 2050 2000..2099 2000 2020 2040 2060 2080
* </pre>
*
* @param pivotYear the pivot year to use as an override when parsing
* @return the new formatter
* @since 1.1
*/
public DateTimeFormatter withPivotYear(int pivotYear) {
return withPivotYear(Integer.valueOf(pivotYear));
}
/**
* Gets the pivot year to use as an override.
*
* @return the pivot year to use as an override
* @since 1.1
*/
public Integer getPivotYear() {
return iPivotYear;
}
//-----------------------------------------------------------------------
/**
* Returns a new formatter that will use the specified default year.
* <p>
* The default year is used when parsing in the case where there is a
* month or a day but not a year. Specifically,
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> IndexOutOfBoundsException if the index is invalid
*/
int getValue(int index);
/**
* Gets the value of one of the fields.
* <p>
* If the field type specified is not supported by the period then zero
* is returned.
*
* @param field the field type to query, null returns zero
* @return the value of that field, zero if field not supported
*/
int get(DurationFieldType field);
/**
* Checks whether the field type specified is supported by this period.
*
* @param field the field to check, may be null which returns false
* @return true if the field is supported
*/
boolean isSupported(DurationFieldType field);
//-----------------------------------------------------------------------
/**
* Get this period as an immutable <code>Period</code> object.
* <p>
* This will either typecast this instance, or create a new <code>Period</code>.
*
* @return a Duration using the same field set and values
*/
Period toPeriod();
/**
* Get this object as a <code>MutablePeriod</code>.
* <p>
* This will always return a new <code>MutablePeriod</code> with the same fields.
*
* @return a MutablePeriod using the same field set and values
*/
MutablePeriod toMutablePeriod();
//-----------------------------------------------------------------------
/**
* Compares this object with the specified object for equality based
* on the value and type of each supported field.
* All ReadablePeriod instances are accepted.
* <p>
* Note that a period of 1 day is not equal to a period of 24 hours,
* nor is 1 hour equal to 60 minutes. Only periods with the same amount
* in each field are equal.
* <p>
* This is because periods represent an abstracted definition of a time
* period (eg. a day may not actually be 24 hours, it might be 23 or 25
* at daylight savings boundary).
* <p>
* To compare the actual duration of two periods, convert both to
* {@link Duration}s, an operation that emphasises that the result may
* differ according to the date you choose.
*
* @param readablePeriod a readable period to check against
* @return true if all the field values and types are equal, false if
* not or the period is null or of an incorrect type
*/
boolean equals(Object readablePeriod);
/**
* Gets a hash code for the period that is compatible with the equals method.
* The hashcode is calculated as follows:
* <pre>
* int total = 17;
* for (int i = 0; i < fields.length; i++) {
* total = 27 * total + getValue(i);
* total = 27 * total + getFieldType(i).hashCode();
* }
* return total;
* </pre>
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
* The yearOfEra field produces results compatible with GregorianCalendar.
* <p>
* The Julian calendar does not have a year zero, and so year -1 is followed by
* year 1. If the Gregorian cutover date is specified at or before year -1
* (Julian), year zero is defined. In other words, the proleptic Gregorian
* chronology used by this class has a year zero.
* <p>
* To create a pure proleptic Julian chronology, use {@link JulianChronology},
* and to create a pure proleptic Gregorian chronology, use
* {@link GregorianChronology}.
* <p>
* GJChronology is thread-safe and immutable.
*
* @author Brian S O'Neill
* @author Stephen Colebourne
* @since 1.0
*/
public final class GJChronology extends AssembledChronology {
/** Serialization lock */
private static final long serialVersionUID = -2545574827706931671L;
/**
* Convert a datetime from one chronology to another.
*/
private static long convertByYear(long instant, Chronology from, Chronology to) {
return to.getDateTimeMillis
(from.year().get(instant),
from.monthOfYear().get(instant),
from.dayOfMonth().get(instant),
from.millisOfDay().get(instant));
}
/**
* Convert a datetime from one chronology to another.
*/
private static long convertByWeekyear(final long instant, Chronology from, Chronology to) {
long newInstant;
newInstant = to.weekyear().set(0, from.weekyear().get(instant));
newInstant = to.weekOfWeekyear().set(newInstant, from.weekOfWeekyear().get(instant));
newInstant = to.dayOfWeek().set(newInstant, from.dayOfWeek().get(instant));
newInstant = to.millisOfDay().set(newInstant, from.millisOfDay().get(instant));
return newInstant;
}
/**
* The default GregorianJulian cutover point.
*/
static final Instant DEFAULT_CUTOVER = new Instant(-12219292800000L);
/** Cache of zone to chronology list */
private static final Map<DateTimeZone, ArrayList<GJChronology>> cCache = new HashMap<DateTimeZone, ArrayList<GJChronology>>();
/**
* Factory method returns instances of the default GJ cutover
* chronology. This uses a cutover date of October 15, 1582 (Gregorian)
* 00:00:00 UTC. For this value, October 4, 1582 (Julian)
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>regorianCutover) {
return getInstance(zone, gregorianCutover, 4);
}
/**
* Factory method returns instances of the GJ cutover chronology. Any
* cutover date may be specified.
*
* @param zone the time zone to use, null is default
* @param gregorianCutover the cutover to use, null means default
* @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4
*/
public static synchronized GJChronology getInstance(
DateTimeZone zone,
ReadableInstant gregorianCutover,
int minDaysInFirstWeek) {
zone = DateTimeUtils.getZone(zone);
Instant cutoverInstant;
if (gregorianCutover == null) {
cutoverInstant = DEFAULT_CUTOVER;
} else {
cutoverInstant = gregorianCutover.toInstant();
}
GJChronology chrono;
ArrayList<GJChronology> chronos = cCache.get(zone);
if (chronos == null) {
chronos = new ArrayList<GJChronology>(2);
cCache.put(zone, chronos);
} else {
for (int i=chronos.size(); --i>=0; ) {
chrono = chronos.get(i);
if (minDaysInFirstWeek == chrono.getMinimumDaysInFirstWeek() &&
cutoverInstant.equals(chrono.getGregorianCutover())) {
return chrono;
}
}
}
if (zone == DateTimeZone.UTC) {
chrono = new GJChronology
(JulianChronology.getInstance(zone, minDaysInFirstWeek),
GregorianChronology.getInstance(zone, minDaysInFirstWeek),
cutoverInstant);
} else {
chrono = getInstance(DateTimeZone.UTC, cutoverInstant, minDaysInFirstWeek);
chrono = new GJChronology
(ZonedChronology.getInstance(chrono, zone),
chrono.iJulianChronology,
chrono.iGregorianChronology,
chrono.iCutoverInstant);
}
chronos.add(chrono);
return chrono;
}
/**
* Factory method returns instances of the GJ cutover chronology. Any
* cutover date may be specified.
*
* @param zone the time zone to use, null is default
* @param gregorianCutover the cutover to use
* @param minDaysInFirstWeek minimum number of days in first week of the year; default is 4
*/
public static GJChronology getInstance(
DateTimeZone zone,
long gregorianCutover,
int minDaysInFirstWeek) {
Instant cutoverInstant;
if (gregorianCutover == DEFAULT_CUTOVER.getMillis())
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> {
cutoverInstant = null;
} else {
cutoverInstant = new Instant(gregorianCutover);
}
return getInstance(zone, cutoverInstant, minDaysInFirstWeek);
}
//-----------------------------------------------------------------------
private JulianChronology iJulianChronology;
private GregorianChronology iGregorianChronology;
private Instant iCutoverInstant;
private long iCutoverMillis;
private long iGapDuration;
/**
* @param julian chronology used before the cutover instant
* @param gregorian chronology used at and after the cutover instant
* @param cutoverInstant instant when the gregorian chronology began
*/
private GJChronology(JulianChronology julian,
GregorianChronology gregorian,
Instant cutoverInstant) {
super(null, new Object[] {julian, gregorian, cutoverInstant});
}
/**
* Called when applying a time zone.
*/
private GJChronology(Chronology base,
JulianChronology julian,
GregorianChronology gregorian,
Instant cutoverInstant) {
super(base, new Object[] {julian, gregorian, cutoverInstant});
}
/**
* Serialization singleton
*/
private Object readResolve() {
return getInstance(getZone(), iCutoverInstant, getMinimumDaysInFirstWeek());
}
public DateTimeZone getZone() {
Chronology base;
if ((base = getBase()) != null) {
return base.getZone();
}
return DateTimeZone.UTC;
}
// Conversion
//-----------------------------------------------------------------------
/**
* Gets the Chronology in the UTC time zone.
*
* @return the chronology in UTC
*/
public Chronology withUTC() {
return withZone(DateTimeZone.UTC);
}
/**
* Gets the Chronology in a specific time zone.
*
* @param zone the zone to get the chronology in, null is default
* @return the chronology
*/
public Chronology withZone(DateTimeZone zone) {
if (zone == null) {
zone = DateTimeZone.getDefault();
}
if (zone == getZone()) {
return this;
}
return getInstance(zone, iCutoverInstant, getMinimumDaysInFirstWeek());
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int millisOfDay)
throws IllegalArgumentException
{
Chronology base;
if ((base = getBase()) != null) {
return base.getDateTimeMillis(year, monthOfYear, dayOfMonth, millisOfDay);
}
// Assume date is Gregorian.
long instant = iGregorianChronology.getDateTimeMillis
(year, monthOfYear, dayOfMonth, millisOfDay);
if (instant < iCutoverMillis)
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> {
// Maybe it's Julian.
instant = iJulianChronology.getDateTimeMillis
(year, monthOfYear, dayOfMonth, millisOfDay);
if (instant >= iCutoverMillis) {
// Okay, it's in the illegal cutover gap.
throw new IllegalArgumentException("Specified date does not exist");
}
}
return instant;
}
public long getDateTimeMillis(int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour,
int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException
{
Chronology base;
if ((base = getBase()) != null) {
return base.getDateTimeMillis
(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
// Assume date is Gregorian.
long instant;
try {
instant = iGregorianChronology.getDateTimeMillis
(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
} catch (IllegalFieldValueException ex) {
if (monthOfYear != 2 || dayOfMonth != 29) {
throw ex;
}
instant = iGregorianChronology.getDateTimeMillis
(year, monthOfYear, 28,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
if (instant >= iCutoverMillis) {
throw ex;
}
}
if (instant < iCutoverMillis) {
// Maybe it's Julian.
instant = iJulianChronology.getDateTimeMillis
(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
if (instant >= iCutoverMillis) {
// Okay, it's in the illegal cutover gap.
throw new IllegalArgumentException("Specified date does not exist");
}
}
return instant;
}
/**
* Gets the cutover instant between Gregorian and Julian chronologies.
* @return the cutover instant
*/
public Instant getGregorianCutover() {
return iCutoverInstant;
}
/**
* Gets the minimum days needed for a week to be the first week in a year.
*
* @return the minimum days
*/
public int getMinimumDaysInFirstWeek() {
return iGregorianChronology.getMinimumDaysInFirstWeek();
}
/**
* Checks if this chronology instance equals another.
*
* @param obj the object to compare to
* @return true if equal
* @since 1.6
*/
public boolean equals(Object obj) {
return super.equals(obj);
}
/**
* A suitable hash code for the chronology.
*
* @return the hash code
* @since 1.6
*/
public int hashCode() {
return "GJ".hashCode() *
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>.yearOfCentury(), fields.yearOfCentury, fields.years, iCutoverMillis);
fields.centuryOfEra = new ImpreciseCutoverField(
julian.centuryOfEra(), fields.centuryOfEra, iCutoverMillis);
fields.centuries = fields.centuryOfEra.getDurationField();
fields.monthOfYear = new ImpreciseCutoverField(
julian.monthOfYear(), fields.monthOfYear, iCutoverMillis);
fields.months = fields.monthOfYear.getDurationField();
fields.weekyear = new ImpreciseCutoverField(
julian.weekyear(), fields.weekyear, null, iCutoverMillis, true);
fields.weekyearOfCentury = new ImpreciseCutoverField(
julian.weekyearOfCentury(), fields.weekyearOfCentury, fields.weekyears, iCutoverMillis);
fields.weekyears = fields.weekyear.getDurationField();
}
// These fields require basic cutover support, except they must link to
// imprecise durations.
{
CutoverField cf = new CutoverField
(julian.dayOfMonth(), fields.dayOfMonth, iCutoverMillis);
cf.iRangeDurationField = fields.months;
fields.dayOfMonth = cf;
}
}
long julianToGregorianByYear(long instant) {
return convertByYear(instant, iJulianChronology, iGregorianChronology);
}
long gregorianToJulianByYear(long instant) {
return convertByYear(instant, iGregorianChronology, iJulianChronology);
}
long julianToGregorianByWeekyear(long instant) {
return convertByWeekyear(instant, iJulianChronology, iGregorianChronology);
}
long gregorianToJulianByWeekyear(long instant) {
return convertByWeekyear(instant, iGregorianChronology, iJulianChronology);
}
//-----------------------------------------------------------------------
/**
* This basic cutover field adjusts calls to 'get' and 'set' methods, and
* assumes that calls to add and addWrapField are unaffected by the cutover.
*/
private class CutoverField extends BaseDateTimeField {
private static final long serialVersionUID = 3528501219481026402L;
final DateTimeField iJulianField;
final DateTimeField iGregorianField;
final long iCutover;
final boolean iConvertByWeekyear;
protected DurationField iDurationField;
protected DurationField iRangeDurationField;
/**
* @param julianField field from the chronology used before the cutover instant
* @param gregorianField field from the chronology used at and
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import java.io.Serializable;
import java.util.Locale;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
/**
* <code>DelegatedDateTimeField</code> delegates each method call to the
* date time field it wraps.
* <p>
* DelegatedDateTimeField is thread-safe and immutable, and its subclasses must
* be as well.
*
* @author Brian S O'Neill
* @since 1.0
* @see DecoratedDateTimeField
*/
public class DelegatedDateTimeField extends DateTimeField implements Serializable {
/** Serialization version */
private static final long serialVersionUID = -4730164440214502503L;
/** The DateTimeField being wrapped */
private final DateTimeField iField;
/** The override field type */
private final DateTimeFieldType iType;
/**
* Constructor.
*
* @param field the field being decorated
*/
public DelegatedDateTimeField(DateTimeField field) {
this(field, null);
}
/**
* Constructor.
*
* @param field the field being decorated
* @param type the field type override
*/
public DelegatedDateTimeField(DateTimeField field, DateTimeFieldType type) {
super();
if (field == null) {
throw new IllegalArgumentException("The field must not be null");
}
iField = field;
iType = (type == null ? field.getType() : type);
}
/**
* Gets the wrapped date time field.
*
* @return the wrapped DateTimeField
*/
public final DateTimeField getWrappedField() {
return iField;
}
public DateTimeFieldType getType() {
return iType;
}
public String getName() {
return iType.getName();
}
public boolean isSupported() {
return iField.isSupported();
}
public boolean isLenient() {
return iField.isLenient();
}
public int get(long instant) {
return iField.get(instant);
}
public
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2009 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Locale;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
/**
* A placeholder implementation to use when a datetime field is not supported.
* <p>
* UnsupportedDateTimeField is thread-safe and immutable.
*
* @author Brian S O'Neill
* @since 1.0
*/
public final class UnsupportedDateTimeField extends DateTimeField implements Serializable {
/** Serialilzation version */
private static final long serialVersionUID = -1934618396111902255L;
/** The cache of unsupported datetime field instances */
private static HashMap<DateTimeFieldType, UnsupportedDateTimeField> cCache;
/**
* Gets an instance of UnsupportedDateTimeField for a specific named field.
* Names should be of standard format, such as 'monthOfYear' or 'hourOfDay'.
* The returned instance is cached.
*
* @param type the type to obtain
* @return the instance
* @throws IllegalArgumentException if durationField is null
*/
public static synchronized UnsupportedDateTimeField getInstance(
DateTimeFieldType type, DurationField durationField) {
UnsupportedDateTimeField field;
if (cCache == null) {
cCache = new HashMap<DateTimeFieldType, UnsupportedDateTimeField>(7);
field = null;
} else {
field = cCache.get(type);
if (field != null && field.getDurationField() != durationField) {
field = null;
}
}
if (field == null) {
field = new UnsupportedDateTimeField(type, durationField);
cCache.put(type, field);
}
return field;
}
/** The field type */
private final DateTimeFieldType iType;
/** The duration of the datetime field */
private final DurationField iDurationField;
/**
* Constructor.
*
* @param type the field type
* @param durationField the duration to use
*/
private UnsupportedDateTimeField(DateTimeFieldType type, DurationField durationField) {
if (
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>type == null || durationField == null) {
throw new IllegalArgumentException();
}
iType = type;
iDurationField = durationField;
}
//-----------------------------------------------------------------------
// Design note: Simple accessors return a suitable value, but methods
// intended to perform calculations throw an UnsupportedOperationException.
public DateTimeFieldType getType() {
return iType;
}
public String getName() {
return iType.getName();
}
/**
* This field is not supported.
*
* @return false always
*/
public boolean isSupported() {
return false;
}
/**
* This field is not lenient.
*
* @return false always
*/
public boolean isLenient() {
return false;
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public int get(long instant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsText(long instant, Locale locale) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsText(long instant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsText(ReadablePartial partial, int fieldValue, Locale locale) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsText(ReadablePartial partial, Locale locale) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsText(int fieldValue, Locale locale) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsShortText(long instant, Locale locale) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsShortText(long instant) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsShortText(ReadablePartial partial, int fieldValue, Locale locale) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsShortText(ReadablePartial partial, Locale locale) {
throw unsupported();
}
/**
* Always throws UnsupportedOperationException
*
* @throws UnsupportedOperationException
*/
public String getAsShortText(int fieldValue, Locale locale) {
throw unsupported();
}
/**
* Delegates to the duration field.
*
* @throws UnsupportedOperationException if the duration is unsupported
*/
public long add(long instant, int value) {
return getDurationField().add(instant, value);
}
/**
* Delegates to the duration field.
*
* @throws UnsupportedOperationException if the duration is unsupported
*/
public long add(long instant, long value) {
return getDurationField().
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>SecondOfMinuteField;
private static final DateTimeField cSecondOfDayField;
private static final DateTimeField cMinuteOfHourField;
private static final DateTimeField cMinuteOfDayField;
private static final DateTimeField cHourOfDayField;
private static final DateTimeField cHourOfHalfdayField;
private static final DateTimeField cClockhourOfDayField;
private static final DateTimeField cClockhourOfHalfdayField;
private static final DateTimeField cHalfdayOfDayField;
static {
cMillisField = MillisDurationField.INSTANCE;
cSecondsField = new PreciseDurationField
(DurationFieldType.seconds(), DateTimeConstants.MILLIS_PER_SECOND);
cMinutesField = new PreciseDurationField
(DurationFieldType.minutes(), DateTimeConstants.MILLIS_PER_MINUTE);
cHoursField = new PreciseDurationField
(DurationFieldType.hours(), DateTimeConstants.MILLIS_PER_HOUR);
cHalfdaysField = new PreciseDurationField
(DurationFieldType.halfdays(), DateTimeConstants.MILLIS_PER_DAY / 2);
cDaysField = new PreciseDurationField
(DurationFieldType.days(), DateTimeConstants.MILLIS_PER_DAY);
cWeeksField = new PreciseDurationField
(DurationFieldType.weeks(), DateTimeConstants.MILLIS_PER_WEEK);
cMillisOfSecondField = new PreciseDateTimeField
(DateTimeFieldType.millisOfSecond(), cMillisField, cSecondsField);
cMillisOfDayField = new PreciseDateTimeField
(DateTimeFieldType.millisOfDay(), cMillisField, cDaysField);
cSecondOfMinuteField = new PreciseDateTimeField
(DateTimeFieldType.secondOfMinute(), cSecondsField, cMinutesField);
cSecondOfDayField = new PreciseDateTimeField
(DateTimeFieldType.secondOfDay(), cSecondsField, cDaysField);
cMinuteOfHourField = new PreciseDateTimeField
(DateTimeFieldType.minuteOfHour(), cMinutesField, cHoursField);
cMinuteOfDayField = new PreciseDateTimeField
(DateTimeFieldType.minuteOfDay(), cMinutesField, cDaysField);
cHourOfDayField = new PreciseDateTimeField
(DateTimeFieldType.hourOfDay(), cHoursField, cDaysField);
cHourOfHalfdayField = new PreciseDateTimeField
(DateTimeFieldType.hourOfHalfday(), cHoursField, cHalfdaysField);
cClockhourOfDayField = new ZeroIsMaxDateTimeField
(cHourOfDayField, DateTimeFieldType.clockhourOfDay());
cClockhourOfHalfdayField = new ZeroIsMaxDateTimeField
(cHourOfHalfdayField, DateTimeFieldType.clockhourOfHalfday());
cHalfdayOfDayField = new HalfdayField();
}
private static final int CACHE_SIZE = 1 << 10;
private static final int CACHE_MASK = CACHE_SIZE - 1;
private transient final YearInfo[] iYearInfoCache = new YearInfo[CACHE_SIZE];
private final int iMinDaysIn
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>FirstWeek;
BasicChronology(Chronology base, Object param, int minDaysInFirstWeek) {
super(base, param);
if (minDaysInFirstWeek < 1 || minDaysInFirstWeek > 7) {
throw new IllegalArgumentException
("Invalid min days in first week: " + minDaysInFirstWeek);
}
iMinDaysInFirstWeek = minDaysInFirstWeek;
}
public DateTimeZone getZone() {
Chronology base;
if ((base = getBase()) != null) {
return base.getZone();
}
return DateTimeZone.UTC;
}
public long getDateTimeMillis(
int year, int monthOfYear, int dayOfMonth, int millisOfDay)
throws IllegalArgumentException {
Chronology base;
if ((base = getBase()) != null) {
return base.getDateTimeMillis(year, monthOfYear, dayOfMonth, millisOfDay);
}
FieldUtils.verifyValueBounds
(DateTimeFieldType.millisOfDay(), millisOfDay, 0, DateTimeConstants.MILLIS_PER_DAY - 1);
return getDateMidnightMillis(year, monthOfYear, dayOfMonth) + millisOfDay;
}
public long getDateTimeMillis(
int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException {
Chronology base;
if ((base = getBase()) != null) {
return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);
return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
+ hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
+ minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
+ secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
+ millisOfSecond;
}
public int getMinimumDaysInFirstWeek() {
return iMinDaysInFirstWeek;
}
/**
* Checks if this chronology instance equals another.
*
* @param obj the object to compare to
* @return true if equal
* @since 1.6
*/
public boolean equals(Object obj) {
return super.equals(obj);
}
/**
* A suitable hash code for the chronology.
*
* @return the hash code
* @since 1.6
*/
public int hashCode() {
return
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> getClass().getName().hashCode() * 11 + getZone().hashCode() + getMinimumDaysInFirstWeek();
}
// Output
//-----------------------------------------------------------------------
/**
* Gets a debugging toString.
*
* @return a debugging string
*/
public String toString() {
StringBuffer sb = new StringBuffer(60);
String name = getClass().getName();
int index = name.lastIndexOf('.');
if (index >= 0) {
name = name.substring(index + 1);
}
sb.append(name);
sb.append('[');
DateTimeZone zone = getZone();
if (zone != null) {
sb.append(zone.getID());
}
if (getMinimumDaysInFirstWeek() != 4) {
sb.append(",mdfw=");
sb.append(getMinimumDaysInFirstWeek());
}
sb.append(']');
return sb.toString();
}
protected void assemble(Fields fields) {
// First copy fields that are the same for all Gregorian and Julian
// chronologies.
fields.millis = cMillisField;
fields.seconds = cSecondsField;
fields.minutes = cMinutesField;
fields.hours = cHoursField;
fields.halfdays = cHalfdaysField;
fields.days = cDaysField;
fields.weeks = cWeeksField;
fields.millisOfSecond = cMillisOfSecondField;
fields.millisOfDay = cMillisOfDayField;
fields.secondOfMinute = cSecondOfMinuteField;
fields.secondOfDay = cSecondOfDayField;
fields.minuteOfHour = cMinuteOfHourField;
fields.minuteOfDay = cMinuteOfDayField;
fields.hourOfDay = cHourOfDayField;
fields.hourOfHalfday = cHourOfHalfdayField;
fields.clockhourOfDay = cClockhourOfDayField;
fields.clockhourOfHalfday = cClockhourOfHalfdayField;
fields.halfdayOfDay = cHalfdayOfDayField;
// Now create fields that have unique behavior for Gregorian and Julian
// chronologies.
fields.year = new BasicYearDateTimeField(this);
fields.yearOfEra = new GJYearOfEraDateTimeField(fields.year, this);
// Define one-based centuryOfEra and yearOfCentury.
DateTimeField field = new OffsetDateTimeField(
fields.yearOfEra, 99);
fields.centuryOfEra = new DividedDateTimeField(
field, DateTimeFieldType.centuryOfEra(), 100);
field = new RemainderDateTimeField(
(DividedDateTimeField) fields.centuryOfEra);
fields.yearOfCentury = new OffsetDateTimeField(
field, DateTimeFieldType.yearOfCentury(), 1);
fields.era = new GJEraDateTimeField(this);
fields.dayOfWeek = new GJDayOfWeekDateTimeField(this, fields.days);
fields.dayOfMonth =
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> new BasicDayOfMonthDateTimeField(this, fields.days);
fields.dayOfYear = new BasicDayOfYearDateTimeField(this, fields.days);
fields.monthOfYear = new GJMonthOfYearDateTimeField(this);
fields.weekyear = new BasicWeekyearDateTimeField(this);
fields.weekOfWeekyear = new BasicWeekOfWeekyearDateTimeField(this, fields.weeks);
field = new RemainderDateTimeField(
fields.weekyear, DateTimeFieldType.weekyearOfCentury(), 100);
fields.weekyearOfCentury = new OffsetDateTimeField(
field, DateTimeFieldType.weekyearOfCentury(), 1);
// The remaining (imprecise) durations are available from the newly
// created datetime fields.
fields.years = fields.year.getDurationField();
fields.centuries = fields.centuryOfEra.getDurationField();
fields.months = fields.monthOfYear.getDurationField();
fields.weekyears = fields.weekyear.getDurationField();
}
//-----------------------------------------------------------------------
/**
* Get the number of days in the year.
*
* @return 366
*/
int getDaysInYearMax() {
return 366;
}
/**
* Get the number of days in the year.
*
* @param year the year to use
* @return 366 if a leap year, otherwise 365
*/
int getDaysInYear(int year) {
return isLeapYear(year) ? 366 : 365;
}
/**
* Get the number of weeks in the year.
*
* @param year the year to use
* @return number of weeks in the year
*/
int getWeeksInYear(int year) {
long firstWeekMillis1 = getFirstWeekOfYearMillis(year);
long firstWeekMillis2 = getFirstWeekOfYearMillis(year + 1);
return (int) ((firstWeekMillis2 - firstWeekMillis1) / DateTimeConstants.MILLIS_PER_WEEK);
}
/**
* Get the millis for the first week of a year.
*
* @param year the year to use
* @return millis
*/
long getFirstWeekOfYearMillis(int year) {
long jan1millis = getYearMillis(year);
int jan1dayOfWeek = getDayOfWeek(jan1millis);
if (jan1dayOfWeek > (8 - iMinDaysInFirstWeek)) {
// First week is end of previous year because it doesn't have enough days.
return jan1millis + (8 - jan1dayOfWeek)
* (long)DateTimeConstants.MILLIS_PER_DAY;
} else {
// First week is start of this year because it has enough days.
return jan1millis - (jan1dayOfWeek - 1)
* (long)DateTimeConstants.MILLIS_PER_DAY;
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>1;
}
/**
* Gets the maximum number of days in the month specified by the instant.
*
* @param instant millis from 1970-01-01T00:00:00Z
* @return the maximum number of days in the month
*/
int getDaysInMonthMax(long instant) {
int thisYear = getYear(instant);
int thisMonth = getMonthOfYear(instant, thisYear);
return getDaysInYearMonth(thisYear, thisMonth);
}
/**
* Gets the maximum number of days in the month specified by the instant.
* The value represents what the user is trying to set, and can be
* used to optimise this method.
*
* @param instant millis from 1970-01-01T00:00:00Z
* @param value the value being set
* @return the maximum number of days in the month
*/
int getDaysInMonthMaxForSet(long instant, int value) {
return getDaysInMonthMax(instant);
}
//-----------------------------------------------------------------------
/**
* Gets the milliseconds for a date at midnight.
*
* @param year the year
* @param monthOfYear the month
* @param dayOfMonth the day
* @return the milliseconds
*/
long getDateMidnightMillis(int year, int monthOfYear, int dayOfMonth) {
FieldUtils.verifyValueBounds(DateTimeFieldType.year(), year, getMinYear(), getMaxYear());
FieldUtils.verifyValueBounds(DateTimeFieldType.monthOfYear(), monthOfYear, 1, getMaxMonth(year));
FieldUtils.verifyValueBounds(DateTimeFieldType.dayOfMonth(), dayOfMonth, 1, getDaysInYearMonth(year, monthOfYear));
return getYearMonthDayMillis(year, monthOfYear, dayOfMonth);
}
/**
* Gets the difference between the two instants in years.
*
* @param minuendInstant the first instant
* @param subtrahendInstant the second instant
* @return the difference
*/
abstract long getYearDifference(long minuendInstant, long subtrahendInstant);
/**
* Is the specified year a leap year?
*
* @param year the year to test
* @return true if leap
*/
abstract boolean isLeapYear(int year);
/**
* Gets the number of days in the specified month and year.
*
* @param year the year
* @param month the month
* @return the number of days
*/
abstract int getDaysInYearMonth(int year, int month);
/**
* Gets the maximum days in the specified month.
*
* @param month the month
* @return the max days
*/
abstract int getDaysInMonthMax(int month);
/**
* Gets the total number of millis elapsed in this year at the start
* of the
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
private static class HalfdayField extends PreciseDateTimeField {
private static final long serialVersionUID = 581601443656929254L;
HalfdayField() {
super(DateTimeFieldType.halfdayOfDay(), cHalfdaysField, cDaysField);
}
public String getAsText(int fieldValue, Locale locale) {
return GJLocaleSymbols.forLocale(locale).halfdayValueToText(fieldValue);
}
public long set(long millis, String text, Locale locale) {
return set(millis, GJLocaleSymbols.forLocale(locale).halfdayTextToValue(text));
}
public int getMaximumTextLength(Locale locale) {
return GJLocaleSymbols.forLocale(locale).getHalfdayMaxTextLength();
}
}
private static class YearInfo {
public final int iYear;
public final long iFirstDayMillis;
YearInfo(int year, long firstDayMillis) {
iYear = year;
iFirstDayMillis = firstDayMillis;
}
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
* -20 -20 minute
* --30.040 --30.040 second/milli
* --30 --30 second
* ---.040 ---.040 milli *
* 10-30.040 10-30.040 hour/second/milli *
* 10:20-.040 1020-.040 hour/minute/milli *
* 10-30 10-30 hour/second *
* 10--.040 10--.040 hour/milli *
* -20-.040 -20-.040 minute/milli *
* plus datetime formats like {date}T{time}
* </pre>
* * indiates that this is not an official ISO format and can be excluded
* by passing in <code>strictISO</code> as <code>true</code>.
* <p>
* This method can side effect the input collection of fields.
* If the input collection is modifiable, then each field that was added to
* the formatter will be removed from the collection, including any duplicates.
* If the input collection is unmodifiable then no side effect occurs.
* <p>
* This side effect processing is useful if you need to know whether all
* the fields were converted into the formatter or not. To achieve this,
* pass in a modifiable list, and check that it is empty on exit.
*
* @param fields the fields to get a formatter for, not null,
* updated by the method call unless unmodifiable,
* removing those fields built in the formatter
* @param extended true to use the extended format (with separators)
* @param strictISO true to stick exactly to ISO8601, false to include additional formats
* @return a suitable formatter
* @throws IllegalArgumentException if there is no format for the fields
* @since 1.1
*/
public static DateTimeFormatter forFields(
Collection<DateTimeFieldType> fields,
boolean extended,
boolean strictISO) {
if (fields == null || fields.size() == 0) {
throw new IllegalArgumentException("The fields must not be null or empty");
}
Set<DateTimeFieldType> workingFields = new HashSet<DateTimeFieldType>(fields);
int inputSize = workingFields.size();
boolean reducedPrec = false;
DateTimeFormatterBuilder bld = new DateTimeFormatterBuilder();
// date
if (workingFields.contains(DateTimeFieldType.monthOfYear())) {
reducedPrec = dateByMonth(bld, workingFields, extended, strictISO);
} else if (workingFields.contains(DateTimeFieldType.dayOfYear())) {
reducedPrec = dateByOrdinal(bld, workingFields, extended, strictISO);
} else if (workingFields.contains(DateTime
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>FieldType.weekOfWeekyear())) {
reducedPrec = dateByWeek(bld, workingFields, extended, strictISO);
} else if (workingFields.contains(DateTimeFieldType.dayOfMonth())) {
reducedPrec = dateByMonth(bld, workingFields, extended, strictISO);
} else if (workingFields.contains(DateTimeFieldType.dayOfWeek())) {
reducedPrec = dateByWeek(bld, workingFields, extended, strictISO);
} else if (workingFields.remove(DateTimeFieldType.year())) {
bld.append(yearElement());
reducedPrec = true;
} else if (workingFields.remove(DateTimeFieldType.weekyear())) {
bld.append(weekyearElement());
reducedPrec = true;
}
boolean datePresent = (workingFields.size() < inputSize);
// time
time(bld, workingFields, extended, strictISO, reducedPrec, datePresent);
// result
if (bld.canBuildFormatter() == false) {
throw new IllegalArgumentException("No valid format for fields: " + fields);
}
// side effect the input collection to indicate the processed fields
// handling unmodifiable collections with no side effect
try {
fields.retainAll(workingFields);
} catch (UnsupportedOperationException ex) {
// ignore, so we can handle unmodifiable collections
}
return bld.toFormatter();
}
//-----------------------------------------------------------------------
/**
* Creates a date using the calendar date format.
* Specification reference: 5.2.1.
*
* @param bld the builder
* @param fields the fields
* @param extended true to use extended format
* @param strictISO true to only allow ISO formats
* @return true if reduced precision
* @since 1.1
*/
private static boolean dateByMonth(
DateTimeFormatterBuilder bld,
Collection<DateTimeFieldType> fields,
boolean extended,
boolean strictISO) {
boolean reducedPrec = false;
if (fields.remove(DateTimeFieldType.year())) {
bld.append(yearElement());
if (fields.remove(DateTimeFieldType.monthOfYear())) {
if (fields.remove(DateTimeFieldType.dayOfMonth())) {
// YYYY-MM-DD/YYYYMMDD
appendSeparator(bld, extended);
bld.appendMonthOfYear(2);
appendSeparator(bld, extended);
bld.appendDayOfMonth(2);
} else {
// YYYY-MM/YYYY-MM
bld.appendLiteral('-');
bld.appendMonthOfYear(2);
reducedPrec = true;
}
} else {
if (fields.remove(DateTimeFieldType.dayOfMonth())) {
// YYYY--DD/YYYY--DD (non-iso)
checkNotStrictISO(fields, strictISO);
bld.appendLiteral('-');
bld.appendLiteral('-');
bld.appendDayOfMonth(2);
} else {
// YYYY/YYYY
reducedPrec = true;
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
}
} else if (fields.remove(DateTimeFieldType.monthOfYear())) {
bld.appendLiteral('-');
bld.appendLiteral('-');
bld.appendMonthOfYear(2);
if (fields.remove(DateTimeFieldType.dayOfMonth())) {
// --MM-DD/--MMDD
appendSeparator(bld, extended);
bld.appendDayOfMonth(2);
} else {
// --MM/--MM
reducedPrec = true;
}
} else if (fields.remove(DateTimeFieldType.dayOfMonth())) {
// ---DD/---DD
bld.appendLiteral('-');
bld.appendLiteral('-');
bld.appendLiteral('-');
bld.appendDayOfMonth(2);
}
return reducedPrec;
}
//-----------------------------------------------------------------------
/**
* Creates a date using the ordinal date format.
* Specification reference: 5.2.2.
*
* @param bld the builder
* @param fields the fields
* @param extended true to use extended format
* @param strictISO true to only allow ISO formats
* @since 1.1
*/
private static boolean dateByOrdinal(
DateTimeFormatterBuilder bld,
Collection<DateTimeFieldType> fields,
boolean extended,
boolean strictISO) {
boolean reducedPrec = false;
if (fields.remove(DateTimeFieldType.year())) {
bld.append(yearElement());
if (fields.remove(DateTimeFieldType.dayOfYear())) {
// YYYY-DDD/YYYYDDD
appendSeparator(bld, extended);
bld.appendDayOfYear(3);
} else {
// YYYY/YYYY
reducedPrec = true;
}
} else if (fields.remove(DateTimeFieldType.dayOfYear())) {
// -DDD/-DDD
bld.appendLiteral('-');
bld.appendDayOfYear(3);
}
return reducedPrec;
}
//-----------------------------------------------------------------------
/**
* Creates a date using the calendar date format.
* Specification reference: 5.2.3.
*
* @param bld the builder
* @param fields the fields
* @param extended true to use extended format
* @param strictISO true to only allow ISO formats
* @since 1.1
*/
private static boolean dateByWeek(
DateTimeFormatterBuilder bld,
Collection<DateTimeFieldType> fields,
boolean extended,
boolean strictISO) {
boolean reducedPrec = false;
if (fields.remove(DateTimeFieldType.weekyear())) {
bld.append(weekyearElement());
if (fields.remove(DateTimeFieldType.weekOfWeekyear())) {
appendSeparator(bld, extended);
bld.appendLiteral('W');
bld.appendWeekOfWeekyear(2);
if (fields.remove(DateTimeFieldType.dayOfWeek())) {
// YYYY-WWW-D/YYYYWWWD
appendSeparator(bld, extended);
bld.appendDayOfWeek(1);
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
} else {
// YYYY-WWW/YYYY-WWW
reducedPrec = true;
}
} else {
if (fields.remove(DateTimeFieldType.dayOfWeek())) {
// YYYY-W-D/YYYYW-D (non-iso)
checkNotStrictISO(fields, strictISO);
appendSeparator(bld, extended);
bld.appendLiteral('W');
bld.appendLiteral('-');
bld.appendDayOfWeek(1);
} else {
// YYYY/YYYY
reducedPrec = true;
}
}
} else if (fields.remove(DateTimeFieldType.weekOfWeekyear())) {
bld.appendLiteral('-');
bld.appendLiteral('W');
bld.appendWeekOfWeekyear(2);
if (fields.remove(DateTimeFieldType.dayOfWeek())) {
// -WWW-D/-WWWD
appendSeparator(bld, extended);
bld.appendDayOfWeek(1);
} else {
// -WWW/-WWW
reducedPrec = true;
}
} else if (fields.remove(DateTimeFieldType.dayOfWeek())) {
// -W-D/-W-D
bld.appendLiteral('-');
bld.appendLiteral('W');
bld.appendLiteral('-');
bld.appendDayOfWeek(1);
}
return reducedPrec;
}
//-----------------------------------------------------------------------
/**
* Adds the time fields to the builder.
* Specification reference: 5.3.1.
*
* @param bld the builder
* @param fields the fields
* @param extended whether to use the extended format
* @param strictISO whether to be strict
* @param reducedPrec whether the date was reduced precision
* @param datePresent whether there was a date
* @since 1.1
*/
private static void time(
DateTimeFormatterBuilder bld,
Collection<DateTimeFieldType> fields,
boolean extended,
boolean strictISO,
boolean reducedPrec,
boolean datePresent) {
boolean hour = fields.remove(DateTimeFieldType.hourOfDay());
boolean minute = fields.remove(DateTimeFieldType.minuteOfHour());
boolean second = fields.remove(DateTimeFieldType.secondOfMinute());
boolean milli = fields.remove(DateTimeFieldType.millisOfSecond());
if (!hour && !minute && !second && !milli) {
return;
}
if (hour || minute || second || milli) {
if (strictISO && reducedPrec) {
throw new IllegalArgumentException("No valid ISO8601 format for fields because Date was reduced precision: " + fields);
}
if (datePresent) {
bld.appendLiteral('T');
}
}
if (hour && minute && second || (hour && !second && !milli)) {
// OK - HMSm/HMS/HM/H - valid in combination with date
} else {
if (strictISO && datePresent) {
throw new IllegalArgumentException("No valid ISO86
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>01 format for fields because Time was truncated: " + fields);
}
if (!hour && (minute && second || (minute && !milli) || second)) {
// OK - MSm/MS/M/Sm/S - valid ISO formats
} else {
if (strictISO) {
throw new IllegalArgumentException("No valid ISO8601 format for fields: " + fields);
}
}
}
if (hour) {
bld.appendHourOfDay(2);
} else if (minute || second || milli) {
bld.appendLiteral('-');
}
if (extended && hour && minute) {
bld.appendLiteral(':');
}
if (minute) {
bld.appendMinuteOfHour(2);
} else if (second || milli) {
bld.appendLiteral('-');
}
if (extended && minute && second) {
bld.appendLiteral(':');
}
if (second) {
bld.appendSecondOfMinute(2);
} else if (milli) {
bld.appendLiteral('-');
}
if (milli) {
bld.appendLiteral('.');
bld.appendMillisOfSecond(3);
}
}
//-----------------------------------------------------------------------
/**
* Checks that the iso only flag is not set, throwing an exception if it is.
*
* @param fields the fields
* @param strictISO true if only ISO formats allowed
* @since 1.1
*/
private static void checkNotStrictISO(Collection<DateTimeFieldType> fields, boolean strictISO) {
if (strictISO) {
throw new IllegalArgumentException("No valid ISO8601 format for fields: " + fields);
}
}
/**
* Appends the separator if necessary.
*
* @param bld the builder
* @param extended whether to append the separator
* @param sep the separator
* @since 1.1
*/
private static void appendSeparator(DateTimeFormatterBuilder bld, boolean extended) {
if (extended) {
bld.appendLiteral('-');
}
}
//-----------------------------------------------------------------------
/**
* Returns a generic ISO date parser for parsing dates with a possible zone.
* <p>
* It accepts formats described by the following syntax:
* <pre>
* date = date-element ['T' offset]
* date-element = std-date-element | ord-date-element | week-date-element
* std-date-element = yyyy ['-' MM ['-' dd]]
* ord-date-element = yyyy ['-' DDD]
* week-date-element = xxxx '-W' ww ['-' e]
* offset = 'Z' | (('+' | '-') HH [':' mm [':' ss [('.' | ',') SSS]]])
* </pre>
*/
public static DateTimeFormatter dateParser() {
if (dp == null) {
DateTimeParser t
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> cannot be parsed.
*
* @return a formatter for xxxx-'W'ww-e'T'HH:mm:ssZZ
*/
public static DateTimeFormatter weekDateTimeNoMillis() {
if (wdtx == null) {
wdtx = new DateTimeFormatterBuilder()
.append(weekDate())
.append(tTimeNoMillis())
.toFormatter();
}
return wdtx;
}
//-----------------------------------------------------------------------
/**
* Returns a basic formatter for a full date as four digit year, two digit
* month of year, and two digit day of month (yyyyMMdd).
*
* @return a formatter for yyyyMMdd
*/
public static DateTimeFormatter basicDate() {
if (bd == null) {
bd = new DateTimeFormatterBuilder()
.appendYear(4, 4)
.appendFixedDecimal(DateTimeFieldType.monthOfYear(), 2)
.appendFixedDecimal(DateTimeFieldType.dayOfMonth(), 2)
.toFormatter();
}
return bd;
}
/**
* Returns a basic formatter for a two digit hour of day, two digit minute
* of hour, two digit second of minute, three digit millis, and time zone
* offset (HHmmss.SSSZ).
* The time zone offset is 'Z' for zero, and of the form '\u00b1HHmm' for non-zero.
* The parser is strict by default, thus time string {@code 24:00} cannot be parsed.
*
* @return a formatter for HHmmss.SSSZ
*/
public static DateTimeFormatter basicTime() {
if (bt == null) {
bt = new DateTimeFormatterBuilder()
.appendFixedDecimal(DateTimeFieldType.hourOfDay(), 2)
.appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2)
.appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2)
.appendLiteral('.')
.appendFractionOfSecond(3, 9)
.appendTimeZoneOffset("Z", false, 2, 2)
.toFormatter();
}
return bt;
}
/**
* Returns a basic formatter for a two digit hour of day, two digit minute
* of hour, two digit second of minute, and time zone offset (HHmmssZ).
* The time zone offset is 'Z' for zero, and of the form '\u00b1HHmm' for non-zero.
* The parser is strict by default, thus time string {@code 24:00} cannot be parsed.
*
* @return a formatter for HHmmssZ
*/
public static DateTimeFormatter basicTimeNoMillis() {
if (btx == null) {
btx = new DateTimeFormatterBuilder()
.appendFixedDecimal(DateTimeFieldType.hourOfDay(), 2)
.appendFixedDecimal(DateTimeFieldType.minuteOfHour(), 2)
.appendFixedDecimal(DateTimeFieldType.secondOfMinute(), 2)
.appendTimeZoneOffset("
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> 24:00} cannot be parsed.
*
* @return a formatter for yyyyMMdd'T'HHmmssZ
*/
public static DateTimeFormatter basicDateTimeNoMillis() {
if (bdtx == null) {
bdtx = new DateTimeFormatterBuilder()
.append(basicDate())
.append(basicTTimeNoMillis())
.toFormatter();
}
return bdtx;
}
/**
* Returns a formatter for a full ordinal date, using a four
* digit year and three digit dayOfYear (yyyyDDD).
*
* @return a formatter for yyyyDDD
* @since 1.1
*/
public static DateTimeFormatter basicOrdinalDate() {
if (bod == null) {
bod = new DateTimeFormatterBuilder()
.appendYear(4, 4)
.appendFixedDecimal(DateTimeFieldType.dayOfYear(), 3)
.toFormatter();
}
return bod;
}
/**
* Returns a formatter for a full ordinal date and time, using a four
* digit year and three digit dayOfYear (yyyyDDD'T'HHmmss.SSSZ).
* The time zone offset is 'Z' for zero, and of the form '\u00b1HHmm' for non-zero.
* The parser is strict by default, thus time string {@code 24:00} cannot be parsed.
*
* @return a formatter for yyyyDDD'T'HHmmss.SSSZ
* @since 1.1
*/
public static DateTimeFormatter basicOrdinalDateTime() {
if (bodt == null) {
bodt = new DateTimeFormatterBuilder()
.append(basicOrdinalDate())
.append(basicTTime())
.toFormatter();
}
return bodt;
}
/**
* Returns a formatter for a full ordinal date and time without millis,
* using a four digit year and three digit dayOfYear (yyyyDDD'T'HHmmssZ).
* The time zone offset is 'Z' for zero, and of the form '\u00b1HHmm' for non-zero.
* The parser is strict by default, thus time string {@code 24:00} cannot be parsed.
*
* @return a formatter for yyyyDDD'T'HHmmssZ
* @since 1.1
*/
public static DateTimeFormatter basicOrdinalDateTimeNoMillis() {
if (bodtx == null) {
bodtx = new DateTimeFormatterBuilder()
.append(basicOrdinalDate())
.append(basicTTimeNoMillis())
.toFormatter();
}
return bodtx;
}
/**
* Returns a basic formatter for a full date as four digit weekyear, two
* digit week of weekyear, and one digit day of week (xxxx'W'wwe).
*
* @return a formatter for xxxx'W'wwe
*/
public static DateTimeFormatter basicWeekDate() {
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
if (bwd == null) {
bwd = new DateTimeFormatterBuilder()
.appendWeekyear(4, 4)
.appendLiteral('W')
.appendFixedDecimal(DateTimeFieldType.weekOfWeekyear(), 2)
.appendFixedDecimal(DateTimeFieldType.dayOfWeek(), 1)
.toFormatter();
}
return bwd;
}
/**
* Returns a basic formatter that combines a basic weekyear date and time,
* separated by a 'T' (xxxx'W'wwe'T'HHmmss.SSSZ).
* The time zone offset is 'Z' for zero, and of the form '\u00b1HHmm' for non-zero.
* The parser is strict by default, thus time string {@code 24:00} cannot be parsed.
*
* @return a formatter for xxxx'W'wwe'T'HHmmss.SSSZ
*/
public static DateTimeFormatter basicWeekDateTime() {
if (bwdt == null) {
bwdt = new DateTimeFormatterBuilder()
.append(basicWeekDate())
.append(basicTTime())
.toFormatter();
}
return bwdt;
}
/**
* Returns a basic formatter that combines a basic weekyear date and time
* without millis, separated by a 'T' (xxxx'W'wwe'T'HHmmssZ).
* The time zone offset is 'Z' for zero, and of the form '\u00b1HHmm' for non-zero.
* The parser is strict by default, thus time string {@code 24:00} cannot be parsed.
*
* @return a formatter for xxxx'W'wwe'T'HHmmssZ
*/
public static DateTimeFormatter basicWeekDateTimeNoMillis() {
if (bwdtx == null) {
bwdtx = new DateTimeFormatterBuilder()
.append(basicWeekDate())
.append(basicTTimeNoMillis())
.toFormatter();
}
return bwdtx;
}
//-----------------------------------------------------------------------
/**
* Returns a formatter for a four digit year. (yyyy)
*
* @return a formatter for yyyy
*/
public static DateTimeFormatter year() {
return yearElement();
}
/**
* Returns a formatter for a four digit year and two digit month of
* year. (yyyy-MM)
*
* @return a formatter for yyyy-MM
*/
public static DateTimeFormatter yearMonth() {
if (ym == null) {
ym = new DateTimeFormatterBuilder()
.append(yearElement())
.append(monthElement())
.toFormatter();
}
return ym;
}
/**
* Returns a formatter for a four digit year, two digit month of year, and
* two digit day of month. (yyyy-MM-dd)
*
* @return a formatter for yyyy-MM-dd
*/
public static DateTimeFormatter
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.tz;
import org.joda.time.DateTimeZone;
/**
* Basic DateTimeZone implementation that has a fixed name key and offsets.
* <p>
* FixedDateTimeZone is thread-safe and immutable.
*
* @author Brian S O'Neill
* @since 1.0
*/
public final class FixedDateTimeZone extends DateTimeZone {
private static final long serialVersionUID = -3513011772763289092L;
private final String iNameKey;
private final int iWallOffset;
private final int iStandardOffset;
public FixedDateTimeZone(String id, String nameKey,
int wallOffset, int standardOffset) {
super(id);
iNameKey = nameKey;
iWallOffset = wallOffset;
iStandardOffset = standardOffset;
}
public String getNameKey(long instant) {
return iNameKey;
}
public int getOffset(long instant) {
return iWallOffset;
}
public int getStandardOffset(long instant) {
return iStandardOffset;
}
public int getOffsetFromLocal(long instantLocal) {
return iWallOffset;
}
public boolean isFixed() {
return true;
}
public long nextTransition(long instant) {
return instant;
}
public long previousTransition(long instant) {
return instant;
}
/**
* Override to return the correct timzone instance.
* @since 1.5
*/
public java.util.TimeZone toTimeZone() {
String id = getID();
if (id.length() == 6 && (id.startsWith("+") || id.startsWith("-"))) {
// standard format offset [+-]hh:mm
// our ID is without any prefix, so we need to add the GMT back
return java.util.TimeZone.getTimeZone("GMT" + getID());
}
// unusual offset, so setup a SimpleTimeZone as best we can
return new java.util.SimpleTimeZone(iWallOffset, getID());
}
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof Fixed
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>DateTimeZone) {
FixedDateTimeZone other = (FixedDateTimeZone) obj;
return
getID().equals(other.getID()) &&
iStandardOffset == other.iStandardOffset &&
iWallOffset == other.iWallOffset;
}
return false;
}
public int hashCode() {
return getID().hashCode() + 37 * iStandardOffset + 31 * iWallOffset;
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time;
import java.io.Serializable;
/**
* Identifies a field, such as year or minuteOfHour, in a chronology-neutral way.
* <p>
* A field type defines the type of the field, such as hourOfDay.
* If does not directly enable any calculations, however it does provide a
* {@link #getField(Chronology)} method that returns the actual calculation engine
* for a particular chronology.
* It also provides access to the related {@link DurationFieldType}s.
* <p>
* Instances of <code>DateTimeFieldType</code> are singletons.
* They can be compared using <code>==</code>.
* <p>
* If required, you can create your own field, for example a quarterOfYear.
* You must create a subclass of <code>DateTimeFieldType</code> that defines the field type.
* This class returns the actual calculation engine from {@link #getField(Chronology)}.
* The subclass should implement equals and hashCode.
*
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.0
*/
public abstract class DateTimeFieldType implements Serializable {
/** Serialization version */
private static final long serialVersionUID = -42615285973990L;
/** Ordinal values for standard field types. */
static final byte
ERA = 1,
YEAR_OF_ERA = 2,
CENTURY_OF_ERA = 3,
YEAR_OF_CENTURY = 4,
YEAR = 5,
DAY_OF_YEAR = 6,
MONTH_OF_YEAR = 7,
DAY_OF_MONTH = 8,
WEEKYEAR_OF_CENTURY = 9,
WEEKYEAR = 10,
WEEK_OF_WEEKYEAR = 11,
DAY_OF_WEEK = 12,
HALFDAY_OF_DAY = 13,
HOUR_OF_HALFDAY = 14,
CLOCKHOUR_OF_HALFDAY = 15,
CLOCKHOUR_OF_
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>DAY = 16,
HOUR_OF_DAY = 17,
MINUTE_OF_DAY = 18,
MINUTE_OF_HOUR = 19,
SECOND_OF_DAY = 20,
SECOND_OF_MINUTE = 21,
MILLIS_OF_DAY = 22,
MILLIS_OF_SECOND = 23;
/** The era field type. */
private static final DateTimeFieldType ERA_TYPE = new StandardDateTimeFieldType(
"era", ERA, DurationFieldType.eras(), null);
/** The yearOfEra field type. */
private static final DateTimeFieldType YEAR_OF_ERA_TYPE = new StandardDateTimeFieldType(
"yearOfEra", YEAR_OF_ERA, DurationFieldType.years(), DurationFieldType.eras());
/** The centuryOfEra field type. */
private static final DateTimeFieldType CENTURY_OF_ERA_TYPE = new StandardDateTimeFieldType(
"centuryOfEra", CENTURY_OF_ERA, DurationFieldType.centuries(), DurationFieldType.eras());
/** The yearOfCentury field type. */
private static final DateTimeFieldType YEAR_OF_CENTURY_TYPE = new StandardDateTimeFieldType(
"yearOfCentury", YEAR_OF_CENTURY, DurationFieldType.years(), DurationFieldType.centuries());
/** The year field type. */
private static final DateTimeFieldType YEAR_TYPE = new StandardDateTimeFieldType(
"year", YEAR, DurationFieldType.years(), null);
/** The dayOfYear field type. */
private static final DateTimeFieldType DAY_OF_YEAR_TYPE = new StandardDateTimeFieldType(
"dayOfYear", DAY_OF_YEAR, DurationFieldType.days(), DurationFieldType.years());
/** The monthOfYear field type. */
private static final DateTimeFieldType MONTH_OF_YEAR_TYPE = new StandardDateTimeFieldType(
"monthOfYear", MONTH_OF_YEAR, DurationFieldType.months(), DurationFieldType.years());
/** The dayOfMonth field type. */
private static final DateTimeFieldType DAY_OF_MONTH_TYPE = new StandardDateTimeFieldType(
"dayOfMonth", DAY_OF_MONTH, DurationFieldType.days(), DurationFieldType.months());
/** The weekyearOfCentury field type. */
private static final DateTimeFieldType WEEKYEAR_OF_CENTURY_TYPE = new StandardDateTimeFieldType(
"weekyearOfCentury", WEEKYEAR_OF_CENTURY, DurationFieldType.weekyears(), DurationFieldType.centuries());
/** The weekyear field type. */
private static final DateTimeFieldType WEEKYEAR_TYPE = new StandardDateTimeFieldType(
"weekyear", WEEKYEAR, DurationFieldType.weekyears(), null);
/** The weekOfWeekyear field type. */
private static final DateTimeFieldType WEEK_OF_WEEKYEAR_TYPE = new StandardDateTimeFieldType(
"weekOfWeekyear", WEEK_OF_WEEKYEAR, DurationFieldType.weeks(), DurationFieldType.weekyears
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>());
/** The dayOfWeek field type. */
private static final DateTimeFieldType DAY_OF_WEEK_TYPE = new StandardDateTimeFieldType(
"dayOfWeek", DAY_OF_WEEK, DurationFieldType.days(), DurationFieldType.weeks());
/** The halfday field type. */
private static final DateTimeFieldType HALFDAY_OF_DAY_TYPE = new StandardDateTimeFieldType(
"halfdayOfDay", HALFDAY_OF_DAY, DurationFieldType.halfdays(), DurationFieldType.days());
/** The hourOfHalfday field type. */
private static final DateTimeFieldType HOUR_OF_HALFDAY_TYPE = new StandardDateTimeFieldType(
"hourOfHalfday", HOUR_OF_HALFDAY, DurationFieldType.hours(), DurationFieldType.halfdays());
/** The clockhourOfHalfday field type. */
private static final DateTimeFieldType CLOCKHOUR_OF_HALFDAY_TYPE = new StandardDateTimeFieldType(
"clockhourOfHalfday", CLOCKHOUR_OF_HALFDAY, DurationFieldType.hours(), DurationFieldType.halfdays());
/** The clockhourOfDay field type. */
private static final DateTimeFieldType CLOCKHOUR_OF_DAY_TYPE = new StandardDateTimeFieldType(
"clockhourOfDay", CLOCKHOUR_OF_DAY, DurationFieldType.hours(), DurationFieldType.days());
/** The hourOfDay field type. */
private static final DateTimeFieldType HOUR_OF_DAY_TYPE = new StandardDateTimeFieldType(
"hourOfDay", HOUR_OF_DAY, DurationFieldType.hours(), DurationFieldType.days());
/** The minuteOfDay field type. */
private static final DateTimeFieldType MINUTE_OF_DAY_TYPE = new StandardDateTimeFieldType(
"minuteOfDay", MINUTE_OF_DAY, DurationFieldType.minutes(), DurationFieldType.days());
/** The minuteOfHour field type. */
private static final DateTimeFieldType MINUTE_OF_HOUR_TYPE = new StandardDateTimeFieldType(
"minuteOfHour", MINUTE_OF_HOUR, DurationFieldType.minutes(), DurationFieldType.hours());
/** The secondOfDay field type. */
private static final DateTimeFieldType SECOND_OF_DAY_TYPE = new StandardDateTimeFieldType(
"secondOfDay", SECOND_OF_DAY, DurationFieldType.seconds(), DurationFieldType.days());
/** The secondOfMinute field type. */
private static final DateTimeFieldType SECOND_OF_MINUTE_TYPE = new StandardDateTimeFieldType(
"secondOfMinute", SECOND_OF_MINUTE, DurationFieldType.seconds(), DurationFieldType.minutes());
/** The millisOfDay field type. */
private static final DateTimeFieldType MILLIS_OF_DAY_TYPE = new StandardDateTimeFieldType(
"millisOfDay", MILLIS_OF_DAY, DurationFieldType.millis(), DurationFieldType.days());
/** The millisOfSecond field type. */
private static final DateTimeFieldType MILLIS_OF_SECOND_TYPE = new StandardDateTimeFieldType(
"millisOfSecond", MILLIS_OF_SECOND, DurationFieldType.millis
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(), DurationFieldType.seconds());
/** The name of the field. */
private final String iName;
//-----------------------------------------------------------------------
/**
* Constructor.
*
* @param name the name to use
*/
protected DateTimeFieldType(String name) {
super();
iName = name;
}
//-----------------------------------------------------------------------
/**
* Get the millis of second field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType millisOfSecond() {
return MILLIS_OF_SECOND_TYPE;
}
/**
* Get the millis of day field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType millisOfDay() {
return MILLIS_OF_DAY_TYPE;
}
/**
* Get the second of minute field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType secondOfMinute() {
return SECOND_OF_MINUTE_TYPE;
}
/**
* Get the second of day field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType secondOfDay() {
return SECOND_OF_DAY_TYPE;
}
/**
* Get the minute of hour field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType minuteOfHour() {
return MINUTE_OF_HOUR_TYPE;
}
/**
* Get the minute of day field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType minuteOfDay() {
return MINUTE_OF_DAY_TYPE;
}
/**
* Get the hour of day (0-23) field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType hourOfDay() {
return HOUR_OF_DAY_TYPE;
}
/**
* Get the hour of day (offset to 1-24) field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType clockhourOfDay() {
return CLOCKHOUR_OF_DAY_TYPE;
}
/**
* Get the hour of am/pm (0-11) field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType hourOfHalfday() {
return HOUR_OF_HALFDAY_TYPE;
}
/**
* Get the hour of am/pm (offset to 1-12) field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType clockhourOfHalfday() {
return CLOCKHOUR_OF_HALFDAY_TYPE;
}
/**
* Get the AM(0) PM(1) field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType halfdayOfDay() {
return HALFDAY_OF_DAY_TYPE;
}
//-----------------------------------------------------------------------
/**
* Get the day of week field type.
*
* @
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>return the DateTimeFieldType constant
*/
public static DateTimeFieldType dayOfWeek() {
return DAY_OF_WEEK_TYPE;
}
/**
* Get the day of month field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType dayOfMonth() {
return DAY_OF_MONTH_TYPE;
}
/**
* Get the day of year field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType dayOfYear() {
return DAY_OF_YEAR_TYPE;
}
/**
* Get the week of a week based year field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType weekOfWeekyear() {
return WEEK_OF_WEEKYEAR_TYPE;
}
/**
* Get the year of a week based year field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType weekyear() {
return WEEKYEAR_TYPE;
}
/**
* Get the year of a week based year within a century field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType weekyearOfCentury() {
return WEEKYEAR_OF_CENTURY_TYPE;
}
/**
* Get the month of year field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType monthOfYear() {
return MONTH_OF_YEAR_TYPE;
}
/**
* Get the year field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType year() {
return YEAR_TYPE;
}
/**
* Get the year of era field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType yearOfEra() {
return YEAR_OF_ERA_TYPE;
}
/**
* Get the year of century field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType yearOfCentury() {
return YEAR_OF_CENTURY_TYPE;
}
/**
* Get the century of era field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType centuryOfEra() {
return CENTURY_OF_ERA_TYPE;
}
/**
* Get the era field type.
*
* @return the DateTimeFieldType constant
*/
public static DateTimeFieldType era() {
return ERA_TYPE;
}
//-----------------------------------------------------------------------
/**
* Get the name of the field.
* <p>
* By convention, names follow a pattern of "dddOfRrr", where "ddd" represents
* the (singular) duration unit field name and "Rrr" represents the (singular)
* duration range field name. If the range field is not applicable, then
* the name of the field is simply the (singular) duration field name.
*
* @return field name
*/
public String getName() {
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
return iName;
}
/**
* Get the duration unit of the field.
*
* @return duration unit of the field, never null
*/
public abstract DurationFieldType getDurationType();
/**
* Get the duration range of the field.
*
* @return duration range of the field, null if unbounded
*/
public abstract DurationFieldType getRangeDurationType();
/**
* Gets a suitable field for this type from the given Chronology.
*
* @param chronology the chronology to use, null means ISOChronology in default zone
* @return a suitable field
*/
public abstract DateTimeField getField(Chronology chronology);
/**
* Checks whether this field supported in the given Chronology.
*
* @param chronology the chronology to use, null means ISOChronology in default zone
* @return true if supported
*/
public boolean isSupported(Chronology chronology) {
return getField(chronology).isSupported();
}
/**
* Get a suitable debug string.
*
* @return debug string
*/
public String toString() {
return getName();
}
private static class StandardDateTimeFieldType extends DateTimeFieldType {
/** Serialization version */
private static final long serialVersionUID = -9937958251642L;
/** The ordinal of the standard field type, for switch statements */
private final byte iOrdinal;
/** The unit duration of the field. */
private final transient DurationFieldType iUnitType;
/** The range duration of the field. */
private final transient DurationFieldType iRangeType;
/**
* Constructor.
*
* @param name the name to use
* @param ordinal the byte value for the oridinal index
* @param unitType the unit duration type
* @param rangeType the range duration type
*/
StandardDateTimeFieldType(String name, byte ordinal,
DurationFieldType unitType, DurationFieldType rangeType) {
super(name);
iOrdinal = ordinal;
iUnitType = unitType;
iRangeType = rangeType;
}
/** @inheritdoc */
public DurationFieldType getDurationType() {
return iUnitType;
}
/** @inheritdoc */
public DurationFieldType getRangeDurationType() {
return iRangeType;
}
/** @inheritdoc */
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof StandardDateTimeFieldType) {
return iOrdinal == ((StandardDateTimeFieldType) obj).iOrdinal;
}
return false;
}
/** @inheritdoc */
@Override
public int hashCode() {
return (1 << iOrdinal);
}
/** @inheritdoc */
public DateTimeField getField(Chronology chronology) {
chronology = DateTimeUtils.getChronology(chronology);
switch (iOrdinal) {
case ERA:
return ch
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>ronology.era();
case YEAR_OF_ERA:
return chronology.yearOfEra();
case CENTURY_OF_ERA:
return chronology.centuryOfEra();
case YEAR_OF_CENTURY:
return chronology.yearOfCentury();
case YEAR:
return chronology.year();
case DAY_OF_YEAR:
return chronology.dayOfYear();
case MONTH_OF_YEAR:
return chronology.monthOfYear();
case DAY_OF_MONTH:
return chronology.dayOfMonth();
case WEEKYEAR_OF_CENTURY:
return chronology.weekyearOfCentury();
case WEEKYEAR:
return chronology.weekyear();
case WEEK_OF_WEEKYEAR:
return chronology.weekOfWeekyear();
case DAY_OF_WEEK:
return chronology.dayOfWeek();
case HALFDAY_OF_DAY:
return chronology.halfdayOfDay();
case HOUR_OF_HALFDAY:
return chronology.hourOfHalfday();
case CLOCKHOUR_OF_HALFDAY:
return chronology.clockhourOfHalfday();
case CLOCKHOUR_OF_DAY:
return chronology.clockhourOfDay();
case HOUR_OF_DAY:
return chronology.hourOfDay();
case MINUTE_OF_DAY:
return chronology.minuteOfDay();
case MINUTE_OF_HOUR:
return chronology.minuteOfHour();
case SECOND_OF_DAY:
return chronology.secondOfDay();
case SECOND_OF_MINUTE:
return chronology.secondOfMinute();
case MILLIS_OF_DAY:
return chronology.millisOfDay();
case MILLIS_OF_SECOND:
return chronology.millisOfSecond();
default:
// Shouldn't happen.
throw new InternalError();
}
}
/**
* Ensure a singleton is returned.
*
* @return the singleton type
*/
private Object readResolve() {
switch (iOrdinal) {
case ERA:
return ERA_TYPE;
case YEAR_OF_ERA:
return YEAR_OF_ERA_TYPE;
case CENTURY_OF_ERA:
return CENTURY_OF_ERA_TYPE;
case YEAR_OF_CENTURY:
return YEAR_OF_CENTURY_TYPE;
case YEAR:
return YEAR_TYPE;
case DAY_OF_YEAR:
return DAY_OF_YEAR_TYPE;
case MONTH_OF_YEAR:
return MONTH_OF_YEAR_TYPE;
case DAY_OF_MONTH:
return DAY_OF_MONTH_TYPE;
case WEEKYEAR_OF_CENTURY:
return WEEKYEAR_OF_CENTURY_TYPE;
case WEEK
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> }
return str;
}
protected void assemble(Fields fields) {
if (getBase().getZone() == DateTimeZone.UTC) {
// Use zero based century and year of century.
fields.centuryOfEra = new DividedDateTimeField(
ISOYearOfEraDateTimeField.INSTANCE, DateTimeFieldType.centuryOfEra(), 100);
fields.yearOfCentury = new RemainderDateTimeField(
(DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.yearOfCentury());
fields.weekyearOfCentury = new RemainderDateTimeField(
(DividedDateTimeField) fields.centuryOfEra, DateTimeFieldType.weekyearOfCentury());
fields.centuries = fields.centuryOfEra.getDurationField();
}
}
/**
* Checks if this chronology instance equals another.
*
* @param obj the object to compare to
* @return true if equal
* @since 1.6
*/
public boolean equals(Object obj) {
return super.equals(obj);
}
/**
* A suitable hash code for the chronology.
*
* @return the hash code
* @since 1.6
*/
public int hashCode() {
return "ISO".hashCode() * 11 + getZone().hashCode();
}
/**
* Serialize ISOChronology instances using a small stub. This reduces the
* serialized size, and deserialized instances come from the cache.
*/
private Object writeReplace() {
return new Stub(getZone());
}
private static final class Stub implements Serializable {
private static final long serialVersionUID = -6212696554273812441L;
private transient DateTimeZone iZone;
Stub(DateTimeZone zone) {
iZone = zone;
}
private Object readResolve() {
return ISOChronology.getInstance(iZone);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.writeObject(iZone);
}
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException
{
iZone = (DateTimeZone)in.readObject();
}
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import java.util.Locale;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.DurationFieldType;
import org.joda.time.IllegalFieldValueException;
import org.joda.time.field.BaseDateTimeField;
import org.joda.time.field.FieldUtils;
import org.joda.time.field.UnsupportedDurationField;
/**
* Provides time calculations for the coptic era component of time.
*
* @author Brian S O'Neill
* @author Stephen Colebourne
* @since 1.2, refactored from CopticEraDateTimeField
*/
final class BasicSingleEraDateTimeField extends BaseDateTimeField {
/**
* Value of the era, which will be the same as DateTimeConstants.CE.
*/
private static final int ERA_VALUE = DateTimeConstants.CE;
/**
* Text value of the era.
*/
private final String iEraText;
/**
* Restricted constructor.
*/
BasicSingleEraDateTimeField(String text) {
super(DateTimeFieldType.era());
iEraText = text;
}
/** @inheritDoc */
public boolean isLenient() {
return false;
}
/** @inheritDoc */
public int get(long instant) {
return ERA_VALUE;
}
/** @inheritDoc */
public long set(long instant, int era) {
FieldUtils.verifyValueBounds(this, era, ERA_VALUE, ERA_VALUE);
return instant;
}
/** @inheritDoc */
public long set(long instant, String text, Locale locale) {
if (iEraText.equals(text) == false && "1".equals(text) == false) {
throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
}
return instant;
}
/** @inheritDoc */
public long roundFloor(long instant) {
return Long.MIN_VALUE;
}
/** @inheritDoc */
public long roundCeiling(long instant) {
return Long.MAX_VALUE;
}
/** @inheritDoc
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>.getInstance(PARIS);
// private static final Chronology BUDDHIST_LONDON = BuddhistChronology.getInstance(LONDON);
private static final Chronology BUDDHIST_TOKYO = BuddhistChronology.getInstance(TOKYO);
private static final Chronology BUDDHIST_UTC = BuddhistChronology.getInstanceUTC();
private long TEST_TIME_NOW =
(31L + 28L + 31L + 30L + 31L + 9L -1L) * DateTimeConstants.MILLIS_PER_DAY;
private DateTimeZone zone = null;
public static void main(String[] args) {
junit.textui.TestRunner.run(suite());
}
public static TestSuite suite() {
return new TestSuite(TestMonthDay_Basics.class);
}
public TestMonthDay_Basics(String name) {
super(name);
}
protected void setUp() throws Exception {
DateTimeUtils.setCurrentMillisFixed(TEST_TIME_NOW);
zone = DateTimeZone.getDefault();
DateTimeZone.setDefault(LONDON);
}
protected void tearDown() throws Exception {
DateTimeUtils.setCurrentMillisSystem();
DateTimeZone.setDefault(zone);
zone = null;
}
//-----------------------------------------------------------------------
public void testGet() {
MonthDay test = new MonthDay();
assertEquals(6, test.get(DateTimeFieldType.monthOfYear()));
assertEquals(9, test.get(DateTimeFieldType.dayOfMonth()));
try {
test.get(null);
fail();
} catch (IllegalArgumentException ex) {}
try {
test.get(DateTimeFieldType.year());
fail();
} catch (IllegalArgumentException ex) {}
}
public void testSize() {
MonthDay test = new MonthDay();
assertEquals(2, test.size());
}
public void testGetFieldType() {
MonthDay test = new MonthDay(COPTIC_PARIS);
assertSame(DateTimeFieldType.monthOfYear(), test.getFieldType(0));
assertSame(DateTimeFieldType.dayOfMonth(), test.getFieldType(1));
try {
test.getFieldType(-1);
} catch (IndexOutOfBoundsException ex) {}
try {
test.getFieldType(2);
} catch (IndexOutOfBoundsException ex) {}
}
public void testGetFieldTypes() {
MonthDay test = new MonthDay(COPTIC_PARIS);
DateTimeFieldType[] fields = test.getFieldTypes();
assertEquals(2, fields.length);
assertSame(DateTimeFieldType.monthOfYear(), fields[0]);
assertSame(DateTimeFieldType.dayOfMonth(), fields[1]);
assertNotSame(test.getFieldTypes(), test.getFieldTypes());
}
public void testGetField() {
MonthDay test = new MonthDay(COPTIC_PARIS);
assertSame(COPTIC_UTC.monthOfYear(), test.getField(0));
assertSame(COPTIC_UTC.dayOfMonth(), test.getField(1));
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
try {
test.getField(-1);
} catch (IndexOutOfBoundsException ex) {}
try {
test.getField(2);
} catch (IndexOutOfBoundsException ex) {}
}
public void testGetFields() {
MonthDay test = new MonthDay(COPTIC_PARIS);
DateTimeField[] fields = test.getFields();
assertEquals(2, fields.length);
assertSame(COPTIC_UTC.monthOfYear(), fields[0]);
assertSame(COPTIC_UTC.dayOfMonth(), fields[1]);
assertNotSame(test.getFields(), test.getFields());
}
public void testGetValue() {
MonthDay test = new MonthDay();
assertEquals(6, test.getValue(0));
assertEquals(9, test.getValue(1));
try {
test.getValue(-1);
} catch (IndexOutOfBoundsException ex) {}
try {
test.getValue(2);
} catch (IndexOutOfBoundsException ex) {}
}
public void testGetValues() {
MonthDay test = new MonthDay();
int[] values = test.getValues();
assertEquals(2, values.length);
assertEquals(6, values[0]);
assertEquals(9, values[1]);
assertNotSame(test.getValues(), test.getValues());
}
public void testIsSupported() {
MonthDay test = new MonthDay(COPTIC_PARIS);
assertEquals(false, test.isSupported(DateTimeFieldType.year()));
assertEquals(true, test.isSupported(DateTimeFieldType.monthOfYear()));
assertEquals(true, test.isSupported(DateTimeFieldType.dayOfMonth()));
assertEquals(false, test.isSupported(DateTimeFieldType.hourOfDay()));
}
public void testEqualsHashCode() {
MonthDay test1 = new MonthDay(10, 6, COPTIC_PARIS);
MonthDay test2 = new MonthDay(10, 6, COPTIC_PARIS);
assertEquals(true, test1.equals(test2));
assertEquals(true, test2.equals(test1));
assertEquals(true, test1.equals(test1));
assertEquals(true, test2.equals(test2));
assertEquals(true, test1.hashCode() == test2.hashCode());
assertEquals(true, test1.hashCode() == test1.hashCode());
assertEquals(true, test2.hashCode() == test2.hashCode());
MonthDay test3 = new MonthDay(10, 6);
assertEquals(false, test1.equals(test3));
assertEquals(false, test2.equals(test3));
assertEquals(false, test3.equals(test1));
assertEquals(false, test3.equals(test2));
assertEquals(false, test1.hashCode() == test3.hashCode());
assertEquals(false, test2.hashCode() == test3.hashCode());
assertEquals(false, test1.equals("Hello"));
assertEquals(true, test1.equals(new MockMD()));
assertEquals(false, test1.equals
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(MockPartial.EMPTY_INSTANCE));
}
class MockMD extends MockPartial {
@Override
public Chronology getChronology() {
return COPTIC_UTC;
}
@Override
public DateTimeField[] getFields() {
return new DateTimeField[] {
COPTIC_UTC.monthOfYear(),
COPTIC_UTC.dayOfMonth()
};
}
@Override
public int[] getValues() {
return new int[] {10, 6};
}
}
//-----------------------------------------------------------------------
public void testCompareTo() {
MonthDay test1 = new MonthDay(6, 6);
MonthDay test1a = new MonthDay(6, 6);
assertEquals(0, test1.compareTo(test1a));
assertEquals(0, test1a.compareTo(test1));
assertEquals(0, test1.compareTo(test1));
assertEquals(0, test1a.compareTo(test1a));
MonthDay test2 = new MonthDay(6, 7);
assertEquals(-1, test1.compareTo(test2));
assertEquals(+1, test2.compareTo(test1));
MonthDay test3 = new MonthDay(6, 7, GregorianChronology.getInstanceUTC());
assertEquals(-1, test1.compareTo(test3));
assertEquals(+1, test3.compareTo(test1));
assertEquals(0, test3.compareTo(test2));
DateTimeFieldType[] types = new DateTimeFieldType[] {
DateTimeFieldType.monthOfYear(),
DateTimeFieldType.dayOfMonth()
};
int[] values = new int[] {6, 6};
Partial p = new Partial(types, values);
assertEquals(0, test1.compareTo(p));
try {
test1.compareTo(null);
fail();
} catch (NullPointerException ex) {}
try {
test1.compareTo(new LocalTime());
fail();
} catch (ClassCastException ex) {}
Partial partial = new Partial()
.with(DateTimeFieldType.centuryOfEra(), 1)
.with(DateTimeFieldType.halfdayOfDay(), 0)
.with(DateTimeFieldType.dayOfMonth(), 9);
try {
new MonthDay(10, 6).compareTo(partial);
fail();
} catch (ClassCastException ex) {}
}
//-----------------------------------------------------------------------
public void testIsEqual_MD() {
MonthDay test1 = new MonthDay(6, 6);
MonthDay test1a = new MonthDay(6, 6);
assertEquals(true, test1.isEqual(test1a));
assertEquals(true, test1a.isEqual(test1));
assertEquals(true, test1.isEqual(test1));
assertEquals(true, test1a.isEqual(test1a));
MonthDay test2 = new MonthDay(6, 7);
assertEquals(false, test1.isEqual(test2));
assertEquals(false, test2.isEqual(test1));
MonthDay test3 = new
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>UTC, base.getChronology());
check(test, 6, 6);
assertEquals(BUDDHIST_UTC, test.getChronology());
}
public void testWithChronologyRetainFields_sameChrono() {
MonthDay base = new MonthDay(6, 6, COPTIC_PARIS);
MonthDay test = base.withChronologyRetainFields(COPTIC_TOKYO);
assertSame(base, test);
}
public void testWithChronologyRetainFields_nullChrono() {
MonthDay base = new MonthDay(6, 6, COPTIC_PARIS);
MonthDay test = base.withChronologyRetainFields(null);
check(base, 6, 6);
assertEquals(COPTIC_UTC, base.getChronology());
check(test, 6, 6);
assertEquals(ISO_UTC, test.getChronology());
}
//-----------------------------------------------------------------------
public void testWithField() {
MonthDay test = new MonthDay(9, 6);
MonthDay result = test.withField(DateTimeFieldType.monthOfYear(), 10);
assertEquals(new MonthDay(9, 6), test);
assertEquals(new MonthDay(10, 6), result);
}
public void testWithField_nullField() {
MonthDay test = new MonthDay(9, 6);
try {
test.withField(null, 6);
fail();
} catch (IllegalArgumentException ex) {}
}
public void testWithField_unknownField() {
MonthDay test = new MonthDay(9, 6);
try {
test.withField(DateTimeFieldType.hourOfDay(), 6);
fail();
} catch (IllegalArgumentException ex) {}
}
public void testWithField_same() {
MonthDay test = new MonthDay(9, 6);
MonthDay result = test.withField(DateTimeFieldType.monthOfYear(), 9);
assertEquals(new MonthDay(9, 6), test);
assertSame(test, result);
}
//-----------------------------------------------------------------------
public void testWithFieldAdded() {
MonthDay test = new MonthDay(9, 6);
MonthDay result = test.withFieldAdded(DurationFieldType.months(), 1);
assertEquals(new MonthDay(9, 6), test);
assertEquals(new MonthDay(10, 6), result);
}
public void testWithFieldAdded_nullField_zero() {
MonthDay test = new MonthDay(9, 6);
try {
test.withFieldAdded(null, 0);
fail();
} catch (IllegalArgumentException ex) {}
}
public void testWithFieldAdded_nullField_nonZero() {
MonthDay test = new MonthDay(9, 6);
try {
test.withFieldAdded(null, 6);
fail();
} catch (IllegalArgumentException ex) {}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>Day expected = new MonthDay(2, 28, ISOChronology.getInstance());
assertEquals(expected, result);
}
public void testMinusDays_int_negativeFromLeap() {
MonthDay test = new MonthDay(2, 29, ISOChronology.getInstanceUTC());
MonthDay result = test.minusDays(-1);
MonthDay expected = new MonthDay(3, 1, ISOChronology.getInstance());
assertEquals(expected, result);
}
public void testMinusDays_same() {
MonthDay test = new MonthDay(5, 11, BuddhistChronology.getInstance());
MonthDay result = test.minusDays(0);
assertSame(test, result);
}
//-----------------------------------------------------------------------
public void testToLocalDate() {
MonthDay base = new MonthDay(6, 6, COPTIC_UTC);
LocalDate test = base.toLocalDate(2009);
assertEquals(new LocalDate(2009, 6, 6, COPTIC_UTC), test);
try {
base.toLocalDate(0);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testToDateTime_RI() {
MonthDay base = new MonthDay(6, 6, COPTIC_PARIS);
DateTime dt = new DateTime(2002, 1, 3, 4, 5, 6, 7);
DateTime test = base.toDateTime(dt);
check(base, 6, 6);
DateTime expected = dt;
expected = expected.monthOfYear().setCopy(6);
expected = expected.dayOfMonth().setCopy(6);
assertEquals(expected, test);
}
public void testToDateTime_nullRI() {
MonthDay base = new MonthDay(6, 6);
DateTime dt = new DateTime(2002, 1, 3, 4, 5, 6, 7);
DateTimeUtils.setCurrentMillisFixed(dt.getMillis());
DateTime test = base.toDateTime((ReadableInstant) null);
check(base, 6, 6);
DateTime expected = dt;
expected = expected.monthOfYear().setCopy(6);
expected = expected.dayOfMonth().setCopy(6);
assertEquals(expected, test);
}
//-----------------------------------------------------------------------
public void testWithers() {
MonthDay test = new MonthDay(10, 6);
check(test.withMonthOfYear(5), 5, 6);
check(test.withDayOfMonth(2), 10, 2);
try {
test.withMonthOfYear(0);
fail();
} catch (IllegalArgumentException ex) {}
try {
test.withMonthOfYear(13);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testProperty() {
MonthDay test = new MonthDay(6, 6);
assertEquals
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(test.monthOfYear(), test.property(DateTimeFieldType.monthOfYear()));
assertEquals(test.dayOfMonth(), test.property(DateTimeFieldType.dayOfMonth()));
try {
test.property(DateTimeFieldType.millisOfDay());
fail();
} catch (IllegalArgumentException ex) {}
try {
test.property(null);
fail();
} catch (IllegalArgumentException ex) {}
}
//-----------------------------------------------------------------------
public void testSerialization() throws Exception {
MonthDay test = new MonthDay(5, 6, COPTIC_PARIS);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(test);
byte[] bytes = baos.toByteArray();
oos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
MonthDay result = (MonthDay) ois.readObject();
ois.close();
assertEquals(test, result);
assertTrue(Arrays.equals(test.getValues(), result.getValues()));
assertTrue(Arrays.equals(test.getFields(), result.getFields()));
assertEquals(test.getChronology(), result.getChronology());
}
//-----------------------------------------------------------------------
public void testToString() {
MonthDay test = new MonthDay(5, 6);
assertEquals("--05-06", test.toString());
}
//-----------------------------------------------------------------------
public void testToString_String() {
MonthDay test = new MonthDay(5, 6);
assertEquals("05 \ufffd\ufffd", test.toString("MM HH"));
assertEquals("--05-06", test.toString((String) null));
}
//-----------------------------------------------------------------------
public void testToString_String_Locale() {
MonthDay test = new MonthDay(5, 6);
assertEquals("\ufffd 6/5", test.toString("EEE d/M", Locale.ENGLISH));
assertEquals("\ufffd 6/5", test.toString("EEE d/M", Locale.FRENCH));
assertEquals("--05-06", test.toString(null, Locale.ENGLISH));
assertEquals("\ufffd 6/5", test.toString("EEE d/M", null));
assertEquals("--05-06", test.toString(null, null));
}
//-----------------------------------------------------------------------
public void testToString_DTFormatter() {
MonthDay test = new MonthDay(5, 6);
assertEquals("05 \ufffd\ufffd", test.toString(DateTimeFormat.forPattern("MM HH")));
assertEquals("--05-06", test.toString((DateTimeFormatter) null));
}
//-----------------------------------------------------------------------
private void check(MonthDay test, int month, int day) {
assertEquals(month, test.getMonthOfYear());
assertEquals(day, test.getDayOfMonth());
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.ReadablePartial;
/**
* Wraps another field such that zero values are replaced with one more than
* it's maximum. This is particularly useful for implementing an clockhourOfDay
* field, where the midnight value of 0 is replaced with 24.
* <p>
* ZeroIsMaxDateTimeField is thread-safe and immutable.
*
* @author Brian S O'Neill
* @since 1.0
*/
public final class ZeroIsMaxDateTimeField extends DecoratedDateTimeField {
private static final long serialVersionUID = 961749798233026866L;
/**
* Constructor.
*
* @param field the base field
* @param type the field type this field will actually use
* @throws IllegalArgumentException if wrapped field's minimum value is not zero
*/
public ZeroIsMaxDateTimeField(DateTimeField field, DateTimeFieldType type) {
super(field, type);
if (field.getMinimumValue() != 0) {
throw new IllegalArgumentException("Wrapped field's minumum value must be zero");
}
}
public int get(long instant) {
int value = getWrappedField().get(instant);
if (value == 0) {
value = getMaximumValue();
}
return value;
}
public long add(long instant, int value) {
return getWrappedField().add(instant, value);
}
public long add(long instant, long value) {
return getWrappedField().add(instant, value);
}
public long addWrapField(long instant, int value) {
return getWrappedField().addWrapField(instant, value);
}
public int[] addWrapField(ReadablePartial instant, int fieldIndex, int[] values, int valueToAdd) {
return getWrappedField().addWrapField(instant, fieldIndex, values, valueToAdd);
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
return getWrappedField().get
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.DurationFieldType;
/**
* Abstract datetime field class that defines its own DurationField, which
* delegates back into this ImpreciseDateTimeField.
* <p>
* This DateTimeField is useful for defining DateTimeFields that are composed
* of imprecise durations. If both duration fields are precise, then a
* {@link PreciseDateTimeField} should be used instead.
* <p>
* When defining imprecise DateTimeFields where a matching DurationField is
* already available, just extend BaseDateTimeField directly so as not to
* create redundant DurationField instances.
* <p>
* ImpreciseDateTimeField is thread-safe and immutable, and its subclasses must
* be as well.
*
* @author Brian S O'Neill
* @see PreciseDateTimeField
* @since 1.0
*/
public abstract class ImpreciseDateTimeField extends BaseDateTimeField {
private static final long serialVersionUID = 7190739608550251860L;
final long iUnitMillis;
private final DurationField iDurationField;
/**
* Constructor.
*
* @param type the field type
* @param unitMillis the average duration unit milliseconds
*/
public ImpreciseDateTimeField(DateTimeFieldType type, long unitMillis) {
super(type);
iUnitMillis = unitMillis;
iDurationField = new LinkedDurationField(type.getDurationType());
}
public abstract int get(long instant);
public abstract long set(long instant, int value);
public abstract long add(long instant, int value);
public abstract long add(long instant, long value);
/**
* Computes the difference between two instants, as measured in the units
* of this field. Any fractional units are dropped from the result. Calling
* getDifference reverses the effect of calling add. In the following code:
*
* <pre>
* long instant = ...
* int v = ...
* int age = getDifference(add(instant, v), instant);
* </pre
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> public abstract long roundFloor(long instant);
protected final long getDurationUnitMillis() {
return iUnitMillis;
}
private final class LinkedDurationField extends BaseDurationField {
private static final long serialVersionUID = -203813474600094134L;
LinkedDurationField(DurationFieldType type) {
super(type);
}
public boolean isPrecise() {
return false;
}
public long getUnitMillis() {
return iUnitMillis;
}
public int getValue(long duration, long instant) {
return ImpreciseDateTimeField.this
.getDifference(instant + duration, instant);
}
public long getValueAsLong(long duration, long instant) {
return ImpreciseDateTimeField.this
.getDifferenceAsLong(instant + duration, instant);
}
public long getMillis(int value, long instant) {
return ImpreciseDateTimeField.this.add(instant, value) - instant;
}
public long getMillis(long value, long instant) {
return ImpreciseDateTimeField.this.add(instant, value) - instant;
}
public long add(long instant, int value) {
return ImpreciseDateTimeField.this.add(instant, value);
}
public long add(long instant, long value) {
return ImpreciseDateTimeField.this.add(instant, value);
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
return ImpreciseDateTimeField.this
.getDifference(minuendInstant, subtrahendInstant);
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
return ImpreciseDateTimeField.this
.getDifferenceAsLong(minuendInstant, subtrahendInstant);
}
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> return WEEKYEARS_TYPE;
}
/**
* Get the months field type.
*
* @return the DateTimeFieldType constant
*/
public static DurationFieldType months() {
return MONTHS_TYPE;
}
/**
* Get the years field type.
*
* @return the DateTimeFieldType constant
*/
public static DurationFieldType years() {
return YEARS_TYPE;
}
/**
* Get the centuries field type.
*
* @return the DateTimeFieldType constant
*/
public static DurationFieldType centuries() {
return CENTURIES_TYPE;
}
/**
* Get the eras field type.
*
* @return the DateTimeFieldType constant
*/
public static DurationFieldType eras() {
return ERAS_TYPE;
}
//-----------------------------------------------------------------------
/**
* Get the name of the field.
* By convention, names are plural.
*
* @return field name
*/
public String getName() {
return iName;
}
/**
* Gets a suitable field for this type from the given Chronology.
*
* @param chronology the chronology to use, null means ISOChronology in default zone
* @return a suitable field
*/
public abstract DurationField getField(Chronology chronology);
/**
* Checks whether this field supported in the given Chronology.
*
* @param chronology the chronology to use, null means ISOChronology in default zone
* @return true if supported
*/
public boolean isSupported(Chronology chronology) {
return getField(chronology).isSupported();
}
/**
* Get a suitable debug string.
*
* @return debug string
*/
public String toString() {
return getName();
}
private static class StandardDurationFieldType extends DurationFieldType {
/** Serialization version */
private static final long serialVersionUID = 31156755687123L;
/** The ordinal of the standard field type, for switch statements */
private final byte iOrdinal;
/**
* Constructor.
*
* @param name the name to use
*/
StandardDurationFieldType(String name, byte ordinal) {
super(name);
iOrdinal = ordinal;
}
/** @inheritdoc */
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof StandardDurationFieldType) {
return iOrdinal == ((StandardDurationFieldType) obj).iOrdinal;
}
return false;
}
/** @inheritdoc */
@Override
public int hashCode() {
return (1 << iOrdinal);
}
public DurationField getField(Chronology chronology) {
chronology = DateTimeUtils.getChronology(chronology);
switch (iOrdinal) {
case ERAS:
return chronology.eras();
case CENTURIES:
return chron
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
}
//-----------------------------------------------------------------------
/**
* Instructs the printer to emit a specific character, and the parser to
* expect it. The parser is case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendLiteral(char c) {
return append0(new CharacterLiteral(c));
}
/**
* Instructs the printer to emit specific text, and the parser to expect
* it. The parser is case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if text is null
*/
public DateTimeFormatterBuilder appendLiteral(String text) {
if (text == null) {
throw new IllegalArgumentException("Literal must not be null");
}
switch (text.length()) {
case 0:
return this;
case 1:
return append0(new CharacterLiteral(text.charAt(0)));
default:
return append0(new StringLiteral(text));
}
}
/**
* Instructs the printer to emit a field value as a decimal number, and the
* parser to expect an unsigned decimal number.
*
* @param fieldType type of field to append
* @param minDigits minimum number of digits to <i>print</i>
* @param maxDigits maximum number of digits to <i>parse</i>, or the estimated
* maximum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null
*/
public DateTimeFormatterBuilder appendDecimal(
DateTimeFieldType fieldType, int minDigits, int maxDigits) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
if (maxDigits < minDigits) {
maxDigits = minDigits;
}
if (minDigits < 0 || maxDigits <= 0) {
throw new IllegalArgumentException();
}
if (minDigits <= 1) {
return append0(new UnpaddedNumber(fieldType, maxDigits, false));
} else {
return append0(new PaddedNumber(fieldType, maxDigits, false, minDigits));
}
}
/**
* Instructs the printer to emit a field value as a fixed-width decimal
* number (smaller numbers will be left-padded with zeros), and the parser
* to expect an unsigned decimal number with the same fixed width.
*
* @param fieldType type of field to append
* @param numDigits the exact number of digits to parse or print, except if
* printed value requires more digits
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null or if <code>numDigits <= 0</code>
* @since 1.5
*/
public DateTimeFormatterBuilder appendFixedDecimal(
DateTimeFieldType fieldType, int numDigits) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
if (numDigits <=
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>0) {
throw new IllegalArgumentException("Illegal number of digits: " + numDigits);
}
return append0(new FixedNumber(fieldType, numDigits, false));
}
/**
* Instructs the printer to emit a field value as a decimal number, and the
* parser to expect a signed decimal number.
*
* @param fieldType type of field to append
* @param minDigits minimum number of digits to <i>print</i>
* @param maxDigits maximum number of digits to <i>parse</i>, or the estimated
* maximum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null
*/
public DateTimeFormatterBuilder appendSignedDecimal(
DateTimeFieldType fieldType, int minDigits, int maxDigits) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
if (maxDigits < minDigits) {
maxDigits = minDigits;
}
if (minDigits < 0 || maxDigits <= 0) {
throw new IllegalArgumentException();
}
if (minDigits <= 1) {
return append0(new UnpaddedNumber(fieldType, maxDigits, true));
} else {
return append0(new PaddedNumber(fieldType, maxDigits, true, minDigits));
}
}
/**
* Instructs the printer to emit a field value as a fixed-width decimal
* number (smaller numbers will be left-padded with zeros), and the parser
* to expect an signed decimal number with the same fixed width.
*
* @param fieldType type of field to append
* @param numDigits the exact number of digits to parse or print, except if
* printed value requires more digits
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null or if <code>numDigits <= 0</code>
* @since 1.5
*/
public DateTimeFormatterBuilder appendFixedSignedDecimal(
DateTimeFieldType fieldType, int numDigits) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
if (numDigits <= 0) {
throw new IllegalArgumentException("Illegal number of digits: " + numDigits);
}
return append0(new FixedNumber(fieldType, numDigits, true));
}
/**
* Instructs the printer to emit a field value as text, and the
* parser to expect text.
*
* @param fieldType type of field to append
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null
*/
public DateTimeFormatterBuilder appendText(DateTimeFieldType fieldType) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
return append0(new TextField(fieldType, false));
}
/**
* Instructs the printer to emit a field value as short text, and the
* parser to expect text.
*
*
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> @param fieldType type of field to append
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null
*/
public DateTimeFormatterBuilder appendShortText(DateTimeFieldType fieldType) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
return append0(new TextField(fieldType, true));
}
/**
* Instructs the printer to emit a remainder of time as a decimal fraction,
* without decimal point. For example, if the field is specified as
* minuteOfHour and the time is 12:30:45, the value printed is 75. A
* decimal point is implied, so the fraction is 0.75, or three-quarters of
* a minute.
*
* @param fieldType type of field to append
* @param minDigits minimum number of digits to print.
* @param maxDigits maximum number of digits to print or parse.
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null
*/
public DateTimeFormatterBuilder appendFraction(
DateTimeFieldType fieldType, int minDigits, int maxDigits) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
if (maxDigits < minDigits) {
maxDigits = minDigits;
}
if (minDigits < 0 || maxDigits <= 0) {
throw new IllegalArgumentException();
}
return append0(new Fraction(fieldType, minDigits, maxDigits));
}
/**
* Appends the print/parse of a fractional second.
* <p>
* This reliably handles the case where fractional digits are being handled
* beyond a visible decimal point. The digits parsed will always be treated
* as the most significant (numerically largest) digits.
* Thus '23' will be parsed as 230 milliseconds.
* Contrast this behaviour to {@link #appendMillisOfSecond}.
* This method does not print or parse the decimal point itself.
*
* @param minDigits minimum number of digits to print
* @param maxDigits maximum number of digits to print or parse
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendFractionOfSecond(int minDigits, int maxDigits) {
return appendFraction(DateTimeFieldType.secondOfDay(), minDigits, maxDigits);
}
/**
* Appends the print/parse of a fractional minute.
* <p>
* This reliably handles the case where fractional digits are being handled
* beyond a visible decimal point. The digits parsed will always be treated
* as the most significant (numerically largest) digits.
* Thus '23' will be parsed as 0.23 minutes (converted to milliseconds).
* This method does not print or parse the decimal point itself.
*
* @param minDigits minimum number of digits to print
* @param maxDigits
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> maximum number of digits to print or parse
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendFractionOfMinute(int minDigits, int maxDigits) {
return appendFraction(DateTimeFieldType.minuteOfDay(), minDigits, maxDigits);
}
/**
* Appends the print/parse of a fractional hour.
* <p>
* This reliably handles the case where fractional digits are being handled
* beyond a visible decimal point. The digits parsed will always be treated
* as the most significant (numerically largest) digits.
* Thus '23' will be parsed as 0.23 hours (converted to milliseconds).
* This method does not print or parse the decimal point itself.
*
* @param minDigits minimum number of digits to print
* @param maxDigits maximum number of digits to print or parse
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendFractionOfHour(int minDigits, int maxDigits) {
return appendFraction(DateTimeFieldType.hourOfDay(), minDigits, maxDigits);
}
/**
* Appends the print/parse of a fractional day.
* <p>
* This reliably handles the case where fractional digits are being handled
* beyond a visible decimal point. The digits parsed will always be treated
* as the most significant (numerically largest) digits.
* Thus '23' will be parsed as 0.23 days (converted to milliseconds).
* This method does not print or parse the decimal point itself.
*
* @param minDigits minimum number of digits to print
* @param maxDigits maximum number of digits to print or parse
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendFractionOfDay(int minDigits, int maxDigits) {
return appendFraction(DateTimeFieldType.dayOfYear(), minDigits, maxDigits);
}
/**
* Instructs the printer to emit a numeric millisOfSecond field.
* <p>
* This method will append a field that prints a three digit value.
* During parsing the value that is parsed is assumed to be three digits.
* If less than three digits are present then they will be counted as the
* smallest parts of the millisecond. This is probably not what you want
* if you are using the field as a fraction. Instead, a fractional
* millisecond should be produced using {@link #appendFractionOfSecond}.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendMillisOfSecond(int minDigits) {
return appendDecimal(DateTimeFieldType.millisOfSecond(), minDigits, 3);
}
/**
* Instructs the printer to emit a numeric millisOfDay field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendMillisOfDay(
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>int minDigits) {
return appendDecimal(DateTimeFieldType.millisOfDay(), minDigits, 8);
}
/**
* Instructs the printer to emit a numeric secondOfMinute field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendSecondOfMinute(int minDigits) {
return appendDecimal(DateTimeFieldType.secondOfMinute(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric secondOfDay field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendSecondOfDay(int minDigits) {
return appendDecimal(DateTimeFieldType.secondOfDay(), minDigits, 5);
}
/**
* Instructs the printer to emit a numeric minuteOfHour field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendMinuteOfHour(int minDigits) {
return appendDecimal(DateTimeFieldType.minuteOfHour(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric minuteOfDay field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendMinuteOfDay(int minDigits) {
return appendDecimal(DateTimeFieldType.minuteOfDay(), minDigits, 4);
}
/**
* Instructs the printer to emit a numeric hourOfDay field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendHourOfDay(int minDigits) {
return appendDecimal(DateTimeFieldType.hourOfDay(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric clockhourOfDay field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendClockhourOfDay(int minDigits) {
return appendDecimal(DateTimeFieldType.clockhourOfDay(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric hourOfHalfday field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendHourOfHalfday(int minDigits) {
return appendDecimal(DateTimeFieldType.hourOfHalfday(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric clockhourOfHalfday field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendClockhourOfHalfday(int minDigits) {
return appendDecimal(DateTimeFieldType.clock
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>hourOfHalfday(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric dayOfWeek field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendDayOfWeek(int minDigits) {
return appendDecimal(DateTimeFieldType.dayOfWeek(), minDigits, 1);
}
/**
* Instructs the printer to emit a numeric dayOfMonth field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendDayOfMonth(int minDigits) {
return appendDecimal(DateTimeFieldType.dayOfMonth(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric dayOfYear field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendDayOfYear(int minDigits) {
return appendDecimal(DateTimeFieldType.dayOfYear(), minDigits, 3);
}
/**
* Instructs the printer to emit a numeric weekOfWeekyear field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendWeekOfWeekyear(int minDigits) {
return appendDecimal(DateTimeFieldType.weekOfWeekyear(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric weekyear field.
*
* @param minDigits minimum number of digits to <i>print</i>
* @param maxDigits maximum number of digits to <i>parse</i>, or the estimated
* maximum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendWeekyear(int minDigits, int maxDigits) {
return appendSignedDecimal(DateTimeFieldType.weekyear(), minDigits, maxDigits);
}
/**
* Instructs the printer to emit a numeric monthOfYear field.
*
* @param minDigits minimum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendMonthOfYear(int minDigits) {
return appendDecimal(DateTimeFieldType.monthOfYear(), minDigits, 2);
}
/**
* Instructs the printer to emit a numeric year field.
*
* @param minDigits minimum number of digits to <i>print</i>
* @param maxDigits maximum number of digits to <i>parse</i>, or the estimated
* maximum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendYear(int minDigits, int maxDigits) {
return appendSignedDecimal(DateTimeFieldType.year(), minDigits, maxDigits);
}
/**
* Instructs the printer to emit a numeric year field which always prints
* and parses
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> two digits. A pivot year is used during parsing to determine
* the range of supported years as <code>(pivot - 50) .. (pivot + 49)</code>.
*
* <pre>
* pivot supported range 00 is 20 is 40 is 60 is 80 is
* ---------------------------------------------------------------
* 1950 1900..1999 1900 1920 1940 1960 1980
* 1975 1925..2024 2000 2020 1940 1960 1980
* 2000 1950..2049 2000 2020 2040 1960 1980
* 2025 1975..2074 2000 2020 2040 2060 1980
* 2050 2000..2099 2000 2020 2040 2060 2080
* </pre>
*
* @param pivot pivot year to use when parsing
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendTwoDigitYear(int pivot) {
return appendTwoDigitYear(pivot, false);
}
/**
* Instructs the printer to emit a numeric year field which always prints
* two digits. A pivot year is used during parsing to determine the range
* of supported years as <code>(pivot - 50) .. (pivot + 49)</code>. If
* parse is instructed to be lenient and the digit count is not two, it is
* treated as an absolute year. With lenient parsing, specifying a positive
* or negative sign before the year also makes it absolute.
*
* @param pivot pivot year to use when parsing
* @param lenientParse when true, if digit count is not two, it is treated
* as an absolute year
* @return this DateTimeFormatterBuilder, for chaining
* @since 1.1
*/
public DateTimeFormatterBuilder appendTwoDigitYear(int pivot, boolean lenientParse) {
return append0(new TwoDigitYear(DateTimeFieldType.year(), pivot, lenientParse));
}
/**
* Instructs the printer to emit a numeric weekyear field which always prints
* and parses two digits. A pivot year is used during parsing to determine
* the range of supported years as <code>(pivot - 50) .. (pivot + 49)</code>.
*
* <pre>
* pivot supported range 00 is 20 is 40 is 60 is 80 is
* ---------------------------------------------------------------
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
* 1950 1900..1999 1900 1920 1940 1960 1980
* 1975 1925..2024 2000 2020 1940 1960 1980
* 2000 1950..2049 2000 2020 2040 1960 1980
* 2025 1975..2074 2000 2020 2040 2060 1980
* 2050 2000..2099 2000 2020 2040 2060 2080
* </pre>
*
* @param pivot pivot weekyear to use when parsing
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendTwoDigitWeekyear(int pivot) {
return appendTwoDigitWeekyear(pivot, false);
}
/**
* Instructs the printer to emit a numeric weekyear field which always prints
* two digits. A pivot year is used during parsing to determine the range
* of supported years as <code>(pivot - 50) .. (pivot + 49)</code>. If
* parse is instructed to be lenient and the digit count is not two, it is
* treated as an absolute weekyear. With lenient parsing, specifying a positive
* or negative sign before the weekyear also makes it absolute.
*
* @param pivot pivot weekyear to use when parsing
* @param lenientParse when true, if digit count is not two, it is treated
* as an absolute weekyear
* @return this DateTimeFormatterBuilder, for chaining
* @since 1.1
*/
public DateTimeFormatterBuilder appendTwoDigitWeekyear(int pivot, boolean lenientParse) {
return append0(new TwoDigitYear(DateTimeFieldType.weekyear(), pivot, lenientParse));
}
/**
* Instructs the printer to emit a numeric yearOfEra field.
*
* @param minDigits minimum number of digits to <i>print</i>
* @param maxDigits maximum number of digits to <i>parse</i>, or the estimated
* maximum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendYearOfEra(int minDigits, int maxDigits) {
return appendDecimal(DateTimeFieldType.yearOfEra(), minDigits, maxDigits);
}
/**
* Instructs the printer to emit a numeric year of century field.
*
* @param minDigits minimum number of digits to print
* @param maxDigits maximum
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> number of digits to <i>parse</i>, or the estimated
* maximum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendYearOfCentury(int minDigits, int maxDigits) {
return appendDecimal(DateTimeFieldType.yearOfCentury(), minDigits, maxDigits);
}
/**
* Instructs the printer to emit a numeric century of era field.
*
* @param minDigits minimum number of digits to print
* @param maxDigits maximum number of digits to <i>parse</i>, or the estimated
* maximum number of digits to print
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendCenturyOfEra(int minDigits, int maxDigits) {
return appendSignedDecimal(DateTimeFieldType.centuryOfEra(), minDigits, maxDigits);
}
/**
* Instructs the printer to emit a locale-specific AM/PM text, and the
* parser to expect it. The parser is case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendHalfdayOfDayText() {
return appendText(DateTimeFieldType.halfdayOfDay());
}
/**
* Instructs the printer to emit a locale-specific dayOfWeek text. The
* parser will accept a long or short dayOfWeek text, case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendDayOfWeekText() {
return appendText(DateTimeFieldType.dayOfWeek());
}
/**
* Instructs the printer to emit a short locale-specific dayOfWeek
* text. The parser will accept a long or short dayOfWeek text,
* case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendDayOfWeekShortText() {
return appendShortText(DateTimeFieldType.dayOfWeek());
}
/**
* Instructs the printer to emit a short locale-specific monthOfYear
* text. The parser will accept a long or short monthOfYear text,
* case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendMonthOfYearText() {
return appendText(DateTimeFieldType.monthOfYear());
}
/**
* Instructs the printer to emit a locale-specific monthOfYear text. The
* parser will accept a long or short monthOfYear text, case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendMonthOfYearShortText() {
return appendShortText(DateTimeFieldType.monthOfYear());
}
/**
* Instructs the printer to emit a locale-specific era text (BC/AD), and
* the parser to expect it. The parser is case-insensitive.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendEraText() {
return appendText
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>(DateTimeFieldType.era());
}
/**
* Instructs the printer to emit a locale-specific time zone name.
* Using this method prevents parsing, because time zone names are not unique.
* See {@link #appendTimeZoneName(Map)}.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendTimeZoneName() {
return append0(new TimeZoneName(TimeZoneName.LONG_NAME, null), null);
}
/**
* Instructs the printer to emit a locale-specific time zone name, providing a lookup for parsing.
* Time zone names are not unique, thus the API forces you to supply the lookup.
* The names are searched in the order of the map, thus it is strongly recommended
* to use a {@code LinkedHashMap} or similar.
*
* @param parseLookup the table of names, not null
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendTimeZoneName(Map<String, DateTimeZone> parseLookup) {
TimeZoneName pp = new TimeZoneName(TimeZoneName.LONG_NAME, parseLookup);
return append0(pp, pp);
}
/**
* Instructs the printer to emit a short locale-specific time zone name.
* Using this method prevents parsing, because time zone names are not unique.
* See {@link #appendTimeZoneShortName(Map)}.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendTimeZoneShortName() {
return append0(new TimeZoneName(TimeZoneName.SHORT_NAME, null), null);
}
/**
* Instructs the printer to emit a short locale-specific time zone
* name, providing a lookup for parsing.
* Time zone names are not unique, thus the API forces you to supply the lookup.
* The names are searched in the order of the map, thus it is strongly recommended
* to use a {@code LinkedHashMap} or similar.
*
* @param parseLookup the table of names, not null
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendTimeZoneShortName(Map<String, DateTimeZone> parseLookup) {
TimeZoneName pp = new TimeZoneName(TimeZoneName.SHORT_NAME, parseLookup);
return append0(pp, pp);
}
/**
* Instructs the printer to emit the identifier of the time zone.
* From version 2.0, this field can be parsed.
*
* @return this DateTimeFormatterBuilder, for chaining
*/
public DateTimeFormatterBuilder appendTimeZoneId() {
return append0(TimeZoneId.INSTANCE, TimeZoneId.INSTANCE);
}
/**
* Instructs the printer to emit text and numbers to display time zone
* offset from UTC. A parser will use the parsed time zone offset to adjust
* the datetime.
* <p>
* If zero offset text is supplied, then it will be printed when the zone is zero.
* During parsing, either the zero
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>
}
}
//-----------------------------------------------------------------------
static class StringLiteral
implements DateTimePrinter, DateTimeParser {
private final String iValue;
StringLiteral(String value) {
super();
iValue = value;
}
public int estimatePrintedLength() {
return iValue.length();
}
public void printTo(
StringBuffer buf, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) {
buf.append(iValue);
}
public void printTo(
Writer out, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
out.write(iValue);
}
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
buf.append(iValue);
}
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
out.write(iValue);
}
public int estimateParsedLength() {
return iValue.length();
}
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
if (text.regionMatches(true, position, iValue, 0, iValue.length())) {
return position + iValue.length();
}
return ~position;
}
}
//-----------------------------------------------------------------------
static abstract class NumberFormatter
implements DateTimePrinter, DateTimeParser {
protected final DateTimeFieldType iFieldType;
protected final int iMaxParsedDigits;
protected final boolean iSigned;
NumberFormatter(DateTimeFieldType fieldType,
int maxParsedDigits, boolean signed) {
super();
iFieldType = fieldType;
iMaxParsedDigits = maxParsedDigits;
iSigned = signed;
}
public int estimateParsedLength() {
return iMaxParsedDigits;
}
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
int limit = Math.min(iMaxParsedDigits, text.length() - position);
boolean negative = false;
int length = 0;
while (length < limit) {
char c = text.charAt(position + length);
if (length == 0 && (c == '-' || c == '+') && iSigned) {
negative = c == '-';
// Next character must be a digit.
if (length + 1 >= limit ||
(c = text.charAt(position + length + 1)) < '0' || c > '9')
{
break;
}
if (negative) {
length++;
} else {
// Skip the '+' for parseInt to succeed.
position++;
}
// Expand the limit to disregard the sign character.
limit = Math.min(limit + 1, text.length() - position);
continue;
}
if (c < '0' || c > '9') {
break;
}
length++;
}
if (length == 0) {
return ~position;
}
int value;
if (length
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> >= 9) {
// Since value may exceed integer limits, use stock parser
// which checks for this.
value = Integer.parseInt(text.substring(position, position += length));
} else {
int i = position;
if (negative) {
i++;
}
try {
value = text.charAt(i++) - '0';
} catch (StringIndexOutOfBoundsException e) {
return ~position;
}
position += length;
while (i < position) {
value = ((value << 3) + (value << 1)) + text.charAt(i++) - '0';
}
if (negative) {
value = -value;
}
}
bucket.saveField(iFieldType, value);
return position;
}
}
//-----------------------------------------------------------------------
static class UnpaddedNumber extends NumberFormatter {
protected UnpaddedNumber(DateTimeFieldType fieldType,
int maxParsedDigits, boolean signed)
{
super(fieldType, maxParsedDigits, signed);
}
public int estimatePrintedLength() {
return iMaxParsedDigits;
}
public void printTo(
StringBuffer buf, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) {
try {
DateTimeField field = iFieldType.getField(chrono);
FormatUtils.appendUnpaddedInteger(buf, field.get(instant));
} catch (RuntimeException e) {
buf.append('\ufffd');
}
}
public void printTo(
Writer out, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
try {
DateTimeField field = iFieldType.getField(chrono);
FormatUtils.writeUnpaddedInteger(out, field.get(instant));
} catch (RuntimeException e) {
out.write('\ufffd');
}
}
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
if (partial.isSupported(iFieldType)) {
try {
FormatUtils.appendUnpaddedInteger(buf, partial.get(iFieldType));
} catch (RuntimeException e) {
buf.append('\ufffd');
}
} else {
buf.append('\ufffd');
}
}
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
if (partial.isSupported(iFieldType)) {
try {
FormatUtils.writeUnpaddedInteger(out, partial.get(iFieldType));
} catch (RuntimeException e) {
out.write('\ufffd');
}
} else {
out.write('\ufffd');
}
}
}
//-----------------------------------------------------------------------
static class PaddedNumber extends NumberFormatter {
protected final int iMinPrintedDigits;
protected PaddedNumber(DateTimeFieldType fieldType, int maxParsedDigits,
boolean signed, int minPrintedDigits)
{
super(fieldType, maxParsedDigits, signed);
iMinPrintedDigits = minPrintedDigits;
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> }
public int estimatePrintedLength() {
return iMaxParsedDigits;
}
public void printTo(
StringBuffer buf, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) {
try {
DateTimeField field = iFieldType.getField(chrono);
FormatUtils.appendPaddedInteger(buf, field.get(instant), iMinPrintedDigits);
} catch (RuntimeException e) {
appendUnknownString(buf, iMinPrintedDigits);
}
}
public void printTo(
Writer out, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
try {
DateTimeField field = iFieldType.getField(chrono);
FormatUtils.writePaddedInteger(out, field.get(instant), iMinPrintedDigits);
} catch (RuntimeException e) {
printUnknownString(out, iMinPrintedDigits);
}
}
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
if (partial.isSupported(iFieldType)) {
try {
FormatUtils.appendPaddedInteger(buf, partial.get(iFieldType), iMinPrintedDigits);
} catch (RuntimeException e) {
appendUnknownString(buf, iMinPrintedDigits);
}
} else {
appendUnknownString(buf, iMinPrintedDigits);
}
}
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
if (partial.isSupported(iFieldType)) {
try {
FormatUtils.writePaddedInteger(out, partial.get(iFieldType), iMinPrintedDigits);
} catch (RuntimeException e) {
printUnknownString(out, iMinPrintedDigits);
}
} else {
printUnknownString(out, iMinPrintedDigits);
}
}
}
//-----------------------------------------------------------------------
static class FixedNumber extends PaddedNumber {
protected FixedNumber(DateTimeFieldType fieldType, int numDigits, boolean signed) {
super(fieldType, numDigits, signed, numDigits);
}
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
int newPos = super.parseInto(bucket, text, position);
if (newPos < 0) {
return newPos;
}
int expectedPos = position + iMaxParsedDigits;
if (newPos != expectedPos) {
if (iSigned) {
char c = text.charAt(position);
if (c == '-' || c == '+') {
expectedPos++;
}
}
if (newPos > expectedPos) {
// The failure is at the position of the first extra digit.
return ~(expectedPos + 1);
} else if (newPos < expectedPos) {
// The failure is at the position where the next digit should be.
return ~newPos;
}
}
return newPos;
}
}
//-----------------------------------------------------------------------
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> static class TwoDigitYear
implements DateTimePrinter, DateTimeParser {
/** The field to print/parse. */
private final DateTimeFieldType iType;
/** The pivot year. */
private final int iPivot;
private final boolean iLenientParse;
TwoDigitYear(DateTimeFieldType type, int pivot, boolean lenientParse) {
super();
iType = type;
iPivot = pivot;
iLenientParse = lenientParse;
}
public int estimateParsedLength() {
return iLenientParse ? 4 : 2;
}
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
int limit = text.length() - position;
if (!iLenientParse) {
limit = Math.min(2, limit);
if (limit < 2) {
return ~position;
}
} else {
boolean hasSignChar = false;
boolean negative = false;
int length = 0;
while (length < limit) {
char c = text.charAt(position + length);
if (length == 0 && (c == '-' || c == '+')) {
hasSignChar = true;
negative = c == '-';
if (negative) {
length++;
} else {
// Skip the '+' for parseInt to succeed.
position++;
limit--;
}
continue;
}
if (c < '0' || c > '9') {
break;
}
length++;
}
if (length == 0) {
return ~position;
}
if (hasSignChar || length != 2) {
int value;
if (length >= 9) {
// Since value may exceed integer limits, use stock
// parser which checks for this.
value = Integer.parseInt(text.substring(position, position += length));
} else {
int i = position;
if (negative) {
i++;
}
try {
value = text.charAt(i++) - '0';
} catch (StringIndexOutOfBoundsException e) {
return ~position;
}
position += length;
while (i < position) {
value = ((value << 3) + (value << 1)) + text.charAt(i++) - '0';
}
if (negative) {
value = -value;
}
}
bucket.saveField(iType, value);
return position;
}
}
int year;
char c = text.charAt(position);
if (c < '0' || c > '9') {
return ~position;
}
year = c - '0';
c = text.charAt(position + 1);
if (c < '0' || c > '9') {
return ~position;
}
year = ((year << 3) + (year << 1)) + c - '0';
int pivot = iPivot;
// If the bucket pivot year is non-null, use that
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> //-----------------------------------------------------------------------
static class TextField
implements DateTimePrinter, DateTimeParser {
private static Map<Locale, Map<DateTimeFieldType, Object[]>> cParseCache =
new HashMap<Locale, Map<DateTimeFieldType, Object[]>>();
private final DateTimeFieldType iFieldType;
private final boolean iShort;
TextField(DateTimeFieldType fieldType, boolean isShort) {
super();
iFieldType = fieldType;
iShort = isShort;
}
public int estimatePrintedLength() {
return iShort ? 6 : 20;
}
public void printTo(
StringBuffer buf, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) {
try {
buf.append(print(instant, chrono, locale));
} catch (RuntimeException e) {
buf.append('\ufffd');
}
}
public void printTo(
Writer out, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) throws IOException {
try {
out.write(print(instant, chrono, locale));
} catch (RuntimeException e) {
out.write('\ufffd');
}
}
public void printTo(StringBuffer buf, ReadablePartial partial, Locale locale) {
try {
buf.append(print(partial, locale));
} catch (RuntimeException e) {
buf.append('\ufffd');
}
}
public void printTo(Writer out, ReadablePartial partial, Locale locale) throws IOException {
try {
out.write(print(partial, locale));
} catch (RuntimeException e) {
out.write('\ufffd');
}
}
private String print(long instant, Chronology chrono, Locale locale) {
DateTimeField field = iFieldType.getField(chrono);
if (iShort) {
return field.getAsShortText(instant, locale);
} else {
return field.getAsText(instant, locale);
}
}
private String print(ReadablePartial partial, Locale locale) {
if (partial.isSupported(iFieldType)) {
DateTimeField field = iFieldType.getField(partial.getChronology());
if (iShort) {
return field.getAsShortText(partial, locale);
} else {
return field.getAsText(partial, locale);
}
} else {
return "\ufffd";
}
}
public int estimateParsedLength() {
return estimatePrintedLength();
}
@SuppressWarnings("unchecked")
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
Locale locale = bucket.getLocale();
// handle languages which might have non ASCII A-Z or punctuation
// bug 1788282
Set<String> validValues = null;
int maxLength = 0;
synchronized (cParseCache) {
Map<DateTimeFieldType, Object[]> innerMap = cParseCache.get(locale);
if (innerMap == null) {
innerMap = new HashMap<DateTimeFieldType,
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> Object[]>();
cParseCache.put(locale, innerMap);
}
Object[] array = innerMap.get(iFieldType);
if (array == null) {
validValues = new HashSet<String>(32);
MutableDateTime dt = new MutableDateTime(0L, DateTimeZone.UTC);
Property property = dt.property(iFieldType);
int min = property.getMinimumValueOverall();
int max = property.getMaximumValueOverall();
if (max - min > 32) { // protect against invalid fields
return ~position;
}
maxLength = property.getMaximumTextLength(locale);
for (int i = min; i <= max; i++) {
property.set(i);
validValues.add(property.getAsShortText(locale));
validValues.add(property.getAsShortText(locale).toLowerCase(locale));
validValues.add(property.getAsShortText(locale).toUpperCase(locale));
validValues.add(property.getAsText(locale));
validValues.add(property.getAsText(locale).toLowerCase(locale));
validValues.add(property.getAsText(locale).toUpperCase(locale));
}
if ("en".equals(locale.getLanguage()) && iFieldType == DateTimeFieldType.era()) {
// hack to support for parsing "BCE" and "CE" if the language is English
validValues.add("BCE");
validValues.add("bce");
validValues.add("CE");
validValues.add("ce");
maxLength = 3;
}
array = new Object[] {validValues, Integer.valueOf(maxLength)};
innerMap.put(iFieldType, array);
} else {
validValues = (Set<String>) array[0];
maxLength = ((Integer) array[1]).intValue();
}
}
// match the longest string first using our knowledge of the max length
int limit = Math.min(text.length(), position + maxLength);
for (int i = limit; i > position; i--) {
String match = text.substring(position, i);
if (validValues.contains(match)) {
bucket.saveField(iFieldType, match, locale);
return i;
}
}
return ~position;
}
}
//-----------------------------------------------------------------------
static class Fraction
implements DateTimePrinter, DateTimeParser {
private final DateTimeFieldType iFieldType;
protected int iMinDigits;
protected int iMaxDigits;
protected Fraction(DateTimeFieldType fieldType, int minDigits, int maxDigits) {
super();
iFieldType = fieldType;
// Limit the precision requirements.
if (maxDigits > 18) {
maxDigits = 18;
}
iMinDigits = minDigits;
iMaxDigits = maxDigits;
}
public int estimatePrintedLength() {
return iMaxDigits;
}
public void printTo(
StringBuffer buf, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> public int estimateParsedLength() {
return iMaxDigits;
}
public int parseInto(DateTimeParserBucket bucket, String text, int position) {
DateTimeField field = iFieldType.getField(bucket.getChronology());
int limit = Math.min(iMaxDigits, text.length() - position);
long value = 0;
long n = field.getDurationField().getUnitMillis() * 10;
int length = 0;
while (length < limit) {
char c = text.charAt(position + length);
if (c < '0' || c > '9') {
break;
}
length++;
long nn = n / 10;
value += (c - '0') * nn;
n = nn;
}
value /= 10;
if (length == 0) {
return ~position;
}
if (value > Integer.MAX_VALUE) {
return ~position;
}
DateTimeField parseField = new PreciseDateTimeField(
DateTimeFieldType.millisOfSecond(),
MillisDurationField.INSTANCE,
field.getDurationField());
bucket.saveField(parseField, (int) value);
return position + length;
}
}
//-----------------------------------------------------------------------
static class TimeZoneOffset
implements DateTimePrinter, DateTimeParser {
private final String iZeroOffsetPrintText;
private final String iZeroOffsetParseText;
private final boolean iShowSeparators;
private final int iMinFields;
private final int iMaxFields;
TimeZoneOffset(String zeroOffsetPrintText, String zeroOffsetParseText,
boolean showSeparators,
int minFields, int maxFields)
{
super();
iZeroOffsetPrintText = zeroOffsetPrintText;
iZeroOffsetParseText = zeroOffsetParseText;
iShowSeparators = showSeparators;
if (minFields <= 0 || maxFields < minFields) {
throw new IllegalArgumentException();
}
if (minFields > 4) {
minFields = 4;
maxFields = 4;
}
iMinFields = minFields;
iMaxFields = maxFields;
}
public int estimatePrintedLength() {
int est = 1 + iMinFields << 1;
if (iShowSeparators) {
est += iMinFields - 1;
}
if (iZeroOffsetPrintText != null && iZeroOffsetPrintText.length() > est) {
est = iZeroOffsetPrintText.length();
}
return est;
}
public void printTo(
StringBuffer buf, long instant, Chronology chrono,
int displayOffset, DateTimeZone displayZone, Locale locale) {
if (displayZone == null) {
return; // no zone
}
if (displayOffset == 0 && iZeroOffsetPrintText != null) {
buf.append(iZeroOffsetPrintText);
return;
}
if (displayOffset >= 0) {
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.chrono;
import java.util.Locale;
import org.joda.time.DateTimeConstants;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
import org.joda.time.DurationFieldType;
import org.joda.time.field.BaseDateTimeField;
import org.joda.time.field.FieldUtils;
import org.joda.time.field.UnsupportedDurationField;
/**
* Provides time calculations for the era component of time.
*
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.0
*/
final class GJEraDateTimeField extends BaseDateTimeField {
/** Serialization version */
private static final long serialVersionUID = 4240986525305515528L;
private final BasicChronology iChronology;
/**
* Restricted constructor
*/
GJEraDateTimeField(BasicChronology chronology) {
super(DateTimeFieldType.era());
iChronology = chronology;
}
public boolean isLenient() {
return false;
}
/**
* Get the Era component of the specified time instant.
*
* @param instant the time instant in millis to query.
*/
public int get(long instant) {
if (iChronology.getYear(instant) <= 0) {
return DateTimeConstants.BCE;
} else {
return DateTimeConstants.CE;
}
}
public String getAsText(int fieldValue, Locale locale) {
return GJLocaleSymbols.forLocale(locale).eraValueToText(fieldValue);
}
/**
* Set the Era component of the specified time instant.
*
* @param instant the time instant in millis to update.
* @param era the era to update the time to.
* @return the updated time instant.
* @throws IllegalArgumentException if era is invalid.
*/
public long set(long instant, int era) {
FieldUtils.verifyValueBounds(this, era, DateTimeConstants.BCE, DateTimeConstants.CE);
int oldEra = get
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time;
import java.util.Locale;
/**
* Defines the calculation engine for date and time fields.
* The interface defines a set of methods that manipulate a millisecond datetime
* with regards to a single field, such as monthOfYear or secondOfMinute.
* <p>
* This design is extensible so, if you wish, you can extract a different field from
* the milliseconds. A number of standard implementations are provided to assist.
*
* @author Guy Allard
* @author Stephen Colebourne
* @author Brian S O'Neill
* @since 1.0
*/
public abstract class DateTimeField {
/**
* Get the type of the field.
*
* @return field type
*/
public abstract DateTimeFieldType getType();
/**
* Get the name of the field.
* <p>
* By convention, names follow a pattern of "dddOfRrr", where "ddd" represents
* the (singular) duration unit field name and "Rrr" represents the (singular)
* duration range field name. If the range field is not applicable, then
* the name of the field is simply the (singular) duration field name.
*
* @return field name
*/
public abstract String getName();
/**
* Returns true if this field is supported.
*
* @return true if this field is supported
*/
public abstract boolean isSupported();
/**
* Returns true if the set method is lenient. If so, it accepts values that
* are out of bounds. For example, a lenient day of month field accepts 32
* for January, converting it to February 1.
*
* @return true if this field is lenient
*/
public abstract boolean isLenient();
// Main access API
//------------------------------------------------------------------------
/**
* Get the value of this field from the milliseconds.
*
* @param instant the milliseconds from 1970-01-01T00:00:00Z to query
* @return the value of the field, in the units of the field
*/
public abstract int get(long instant);
/**
* Get the human-readable, text value of
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DateTimeFieldType;
import org.joda.time.DurationField;
/**
* Precise datetime field, composed of two precise duration fields.
* <p>
* This DateTimeField is useful for defining DateTimeFields that are composed
* of precise durations, like time of day fields. If either duration field is
* imprecise, then an {@link ImpreciseDateTimeField} may be used instead.
* <p>
* PreciseDateTimeField is thread-safe and immutable.
*
* @author Brian S O'Neill
* @author Stephen Colebourne
* @since 1.0
* @see ImpreciseDateTimeField
*/
public class PreciseDateTimeField extends PreciseDurationDateTimeField {
private static final long serialVersionUID = -5586801265774496376L;
/** The maximum range in the correct units */
private final int iRange;
private final DurationField iRangeField;
/**
* Constructor.
*
* @param type the field type this field uses
* @param unit precise unit duration, like "seconds()".
* @param range precise range duration, preferably a multiple of the unit,
* like "minutes()".
* @throws IllegalArgumentException if either duration field is imprecise
* @throws IllegalArgumentException if unit milliseconds is less than one
* or effective value range is less than two.
*/
public PreciseDateTimeField(DateTimeFieldType type,
DurationField unit, DurationField range) {
super(type, unit);
if (!range.isPrecise()) {
throw new IllegalArgumentException("Range duration field must be precise");
}
long rangeMillis = range.getUnitMillis();
iRange = (int)(rangeMillis / getUnitMillis());
if (iRange < 2) {
throw new IllegalArgumentException("The effective range must be at least 2");
}
iRangeField = range;
}
/**
* Get the amount of fractional units from the specified time instant.
*
* @param instant the milliseconds from 1970-01-01T00:00:00Z to query
*
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>Before(ReadableInstant instant);
/**
* Is this time interval entirely before the specified interval.
* <p>
* Intervals are inclusive of the start instant and exclusive of the end.
*
* @param interval the interval to compare to, null means now
* @return true if this time interval is before the interval specified
*/
boolean isBefore(ReadableInterval interval);
//-----------------------------------------------------------------------
/**
* Get this interval as an immutable <code>Interval</code> object.
* <p>
* This will either typecast this instance, or create a new <code>Interval</code>.
*
* @return the interval as an Interval object
*/
Interval toInterval();
/**
* Get this time interval as a <code>MutableInterval</code>.
* <p>
* This will always return a new <code>MutableInterval</code> with the same interval.
*
* @return the time interval as a MutableInterval object
*/
MutableInterval toMutableInterval();
//-----------------------------------------------------------------------
/**
* Gets the millisecond duration of this time interval.
*
* @return the millisecond duration of the time interval
* @throws ArithmeticException if the duration exceeds the capacity of a long
*/
Duration toDuration();
/**
* Gets the millisecond duration of this time interval.
*
* @return the millisecond duration of the time interval
* @throws ArithmeticException if the duration exceeds the capacity of a long
*/
long toDurationMillis();
/**
* Converts the duration of the interval to a period using the
* standard period type.
* <p>
* This method should be used to exract the field values describing the
* difference between the start and end instants.
*
* @return a time period derived from the interval
*/
Period toPeriod();
/**
* Converts the duration of the interval to a period using the
* specified period type.
* <p>
* This method should be used to exract the field values describing the
* difference between the start and end instants.
*
* @param type the requested type of the duration, null means standard
* @return a time period derived from the interval
*/
Period toPeriod(PeriodType type);
//-----------------------------------------------------------------------
/**
* Compares this object with the specified object for equality based
* on start and end millis plus the chronology.
* All ReadableInterval instances are accepted.
* <p>
* To compare the duration of two time intervals, use {@link #toDuration()}
* to get the durations and compare those.
*
* @param readableInterval a readable interval to check against
* @return true if the start and end millis are equal
*/
boolean equals(Object readableInterval);
/**
* Gets a hash code for the time interval that is compatable with the
* equals method.
* <p>
* The formula used must be as follows:
* <pre>int result = 97;
* result =
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>p>
* The recognised object types are defined in
* {@link org.joda.time.convert.ConverterManager ConverterManager} and
* include ReadableInstant, String, Calendar and Date.
*
* @param instant the datetime object
* @param zone the time zone
* @throws IllegalArgumentException if the instant is invalid
*/
public BaseDateTime(Object instant, DateTimeZone zone) {
super();
InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant);
Chronology chrono = checkChronology(converter.getChronology(instant, zone));
iChronology = chrono;
iMillis = checkInstant(converter.getInstantMillis(instant, chrono), chrono);
}
/**
* Constructs an instance from an Object that represents a datetime,
* using the specified chronology.
* <p>
* If the chronology is null, ISO in the default time zone is used.
* <p>
* The recognised object types are defined in
* {@link org.joda.time.convert.ConverterManager ConverterManager} and
* include ReadableInstant, String, Calendar and Date.
*
* @param instant the datetime object
* @param chronology the chronology
* @throws IllegalArgumentException if the instant is invalid
*/
public BaseDateTime(Object instant, Chronology chronology) {
super();
InstantConverter converter = ConverterManager.getInstance().getInstantConverter(instant);
iChronology = checkChronology(converter.getChronology(instant, chronology));
iMillis = checkInstant(converter.getInstantMillis(instant, chronology), iChronology);
}
//-----------------------------------------------------------------------
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the default time zone.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param millisOfSecond the millisecond of the second
*/
public BaseDateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond) {
this(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstance());
}
/**
* Constructs an instance from datetime field values
* using <code>ISOChronology</code> in the specified time zone.
* <p>
* If the specified time zone is null, the default zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param millisOfSecond the millisecond of the second
* @param zone the time zone, null means default time zone
*/
public BaseDateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond,
DateTimeZone zone) {
this(year, monthOfYear, dayOfMonth, hourOfDay,
minuteOfHour, secondOfMinute, millisOfSecond, ISOChronology.getInstance(zone));
}
/**
* Constructs an instance from datetime field values
* using the specified chronology.
* <p>
* If the chronology is null, <code>ISOChronology</code>
* in the default time zone is used.
*
* @param year the year
* @param monthOfYear the month of the year
* @param dayOfMonth the day of the month
* @param hourOfDay the hour of the day
* @param minuteOfHour the minute of the hour
* @param secondOfMinute the second of the minute
* @param millisOfSecond the millisecond of the second
* @param chronology the chronology, null means ISOChronology in default zone
*/
public BaseDateTime(
int year,
int monthOfYear,
int dayOfMonth,
int hourOfDay,
int minuteOfHour,
int secondOfMinute,
int millisOfSecond,
Chronology chronology) {
super();
iChronology = checkChronology(chronology);
long instant = iChronology.getDateTimeMillis(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
iMillis = checkInstant(instant, iChronology);
}
//-----------------------------------------------------------------------
/**
* Checks the specified chronology before storing it, potentially altering it.
* This method must not access any instance variables.
* <p>
* This implementation converts nulls to ISOChronology in the default zone.
*
* @param chronology the chronology to use, may be null
* @return the chronology to store in this datetime, not null
*/
protected Chronology checkChronology(Chronology chronology) {
return DateTimeUtils.getChronology(chronology);
}
/**
* Checks the specified instant before storing it, potentially altering it.
* This method must not access any instance variables.
* <p>
* This implementation simply returns the instant.
*
* @param instant the milliseconds from 1970-01-01T00:00:00Z to round
* @param chronology the ch
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> * @param value the value of the field, which may be negative
* @param instant ignored
* @return the milliseconds that the field represents, which may be
* negative
*/
public long getMillis(long value, long instant) {
return FieldUtils.safeMultiply(value, iUnitMillis);
}
public long add(long instant, int value) {
long addition = value * iUnitMillis; // safe
return FieldUtils.safeAdd(instant, addition);
}
public long add(long instant, long value) {
long addition = FieldUtils.safeMultiply(value, iUnitMillis);
return FieldUtils.safeAdd(instant, addition);
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
long difference = FieldUtils.safeSubtract(minuendInstant, subtrahendInstant);
return difference / iUnitMillis;
}
//-----------------------------------------------------------------------
/**
* Compares this duration field to another.
* Two fields are equal if of the same type and duration.
*
* @param obj the object to compare to
* @return if equal
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof PreciseDurationField) {
PreciseDurationField other = (PreciseDurationField) obj;
return (getType() == other.getType()) && (iUnitMillis == other.iUnitMillis);
}
return false;
}
/**
* Gets a hash code for this instance.
*
* @return a suitable hashcode
*/
public int hashCode() {
long millis = iUnitMillis;
int hash = (int) (millis ^ (millis >>> 32));
hash += getType().hashCode();
return hash;
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2005 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time.field;
import org.joda.time.DurationField;
import org.joda.time.DurationFieldType;
/**
* Scales a DurationField such that it's unit millis becomes larger in
* magnitude.
* <p>
* ScaledDurationField is thread-safe and immutable.
*
* @see PreciseDurationField
*
* @author Brian S O'Neill
* @since 1.0
*/
public class ScaledDurationField extends DecoratedDurationField {
private static final long serialVersionUID = -3205227092378684157L;
private final int iScalar;
/**
* Constructor
*
* @param field the field to wrap, like "year()".
* @param type the type this field will actually use
* @param scalar scalar, such as 100 years in a century
* @throws IllegalArgumentException if scalar is zero or one.
*/
public ScaledDurationField(DurationField field, DurationFieldType type, int scalar) {
super(field, type);
if (scalar == 0 || scalar == 1) {
throw new IllegalArgumentException("The scalar must not be 0 or 1");
}
iScalar = scalar;
}
public int getValue(long duration) {
return getWrappedField().getValue(duration) / iScalar;
}
public long getValueAsLong(long duration) {
return getWrappedField().getValueAsLong(duration) / iScalar;
}
public int getValue(long duration, long instant) {
return getWrappedField().getValue(duration, instant) / iScalar;
}
public long getValueAsLong(long duration, long instant) {
return getWrappedField().getValueAsLong(duration, instant) / iScalar;
}
public long getMillis(int value) {
long scaled = ((long) value) * ((long) iScalar);
return getWrappedField().getMillis(scaled);
}
public long getMillis(long value) {
long scaled = FieldUtils.safeMultiply(value, iScalar);
return getWrappedField().getMillis(scaled);
}
public long getMillis(int value
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>, long instant) {
long scaled = ((long) value) * ((long) iScalar);
return getWrappedField().getMillis(scaled, instant);
}
public long getMillis(long value, long instant) {
long scaled = FieldUtils.safeMultiply(value, iScalar);
return getWrappedField().getMillis(scaled, instant);
}
public long add(long instant, int value) {
long scaled = ((long) value) * ((long) iScalar);
return getWrappedField().add(instant, scaled);
}
public long add(long instant, long value) {
long scaled = FieldUtils.safeMultiply(value, iScalar);
return getWrappedField().add(instant, scaled);
}
public int getDifference(long minuendInstant, long subtrahendInstant) {
return getWrappedField().getDifference(minuendInstant, subtrahendInstant) / iScalar;
}
public long getDifferenceAsLong(long minuendInstant, long subtrahendInstant) {
return getWrappedField().getDifferenceAsLong(minuendInstant, subtrahendInstant) / iScalar;
}
public long getUnitMillis() {
return getWrappedField().getUnitMillis() * iScalar;
}
//-----------------------------------------------------------------------
/**
* Returns the scalar applied, in the field's units.
*
* @return the scalar
*/
public int getScalar() {
return iScalar;
}
/**
* Compares this duration field to another.
* Two fields are equal if of the same type and duration.
*
* @param obj the object to compare to
* @return if equal
*/
public boolean equals(Object obj) {
if (this == obj) {
return true;
} else if (obj instanceof ScaledDurationField) {
ScaledDurationField other = (ScaledDurationField) obj;
return (getWrappedField().equals(other.getWrappedField())) &&
(getType() == other.getType()) &&
(iScalar == other.iScalar);
}
return false;
}
/**
* Gets a hash code for this instance.
*
* @return a suitable hashcode
*/
public int hashCode() {
long scalar = iScalar;
int hash = (int) (scalar ^ (scalar >>> 32));
hash += getType().hashCode();
hash += getWrappedField().hashCode();
return hash;
}
}
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> the value is too large for an int
*/
public abstract int getValue(long duration);
/**
* Get the value of this field from the milliseconds, which is approximate
* if this field is imprecise.
*
* @param duration the milliseconds to query, which may be negative
* @return the value of the field, in the units of the field, which may be
* negative
*/
public abstract long getValueAsLong(long duration);
/**
* Get the value of this field from the milliseconds relative to an
* instant. For precise fields this method produces the same result as for
* the single argument get method.
* <p>
* If the millisecond duration is positive, then the instant is treated as a
* "start instant". If negative, the instant is treated as an "end instant".
*
* @param duration the milliseconds to query, which may be negative
* @param instant the start instant to calculate relative to
* @return the value of the field, in the units of the field, which may be
* negative
* @throws ArithmeticException if the value is too large for an int
*/
public abstract int getValue(long duration, long instant);
/**
* Get the value of this field from the milliseconds relative to an
* instant. For precise fields this method produces the same result as for
* the single argument get method.
* <p>
* If the millisecond duration is positive, then the instant is treated as a
* "start instant". If negative, the instant is treated as an "end instant".
*
* @param duration the milliseconds to query, which may be negative
* @param instant the start instant to calculate relative to
* @return the value of the field, in the units of the field, which may be
* negative
*/
public abstract long getValueAsLong(long duration, long instant);
//------------------------------------------------------------------------
/**
* Get the millisecond duration of this field from its value, which is
* approximate if this field is imprecise.
*
* @param value the value of the field, which may be negative
* @return the milliseconds that the field represents, which may be
* negative
*/
public abstract long getMillis(int value);
/**
* Get the millisecond duration of this field from its value, which is
* approximate if this field is imprecise.
*
* @param value the value of the field, which may be negative
* @return the milliseconds that the field represents, which may be
* negative
*/
public abstract long getMillis(long value);
/**
* Get the millisecond duration of this field from its value relative to an
* instant. For precise fields this method produces the same result as for
* the single argument getMillis method.
* <p>
* If the value is positive, then the instant is treated as a "start
* instant". If negative, the instant is treated as an "end instant".
*
* @param value
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS> chronology to use, null means use base
*/
protected BasePartial(BasePartial base, Chronology chrono) {
super();
iChronology = chrono.withUTC();
iValues = base.iValues;
}
//-----------------------------------------------------------------------
/**
* Gets the value of the field at the specifed index.
*
* @param index the index
* @return the value
* @throws IndexOutOfBoundsException if the index is invalid
*/
public int getValue(int index) {
return iValues[index];
}
/**
* Gets an array of the value of each of the fields that this partial supports.
* <p>
* The fields are returned largest to smallest, for example Hour, Minute, Second.
* Each value corresponds to the same array index as <code>getFields()</code>
*
* @return the current values of each field (cloned), largest to smallest
*/
public int[] getValues() {
return (int[]) iValues.clone();
}
/**
* Gets the chronology of the partial which is never null.
* <p>
* The {@link Chronology} is the calculation engine behind the partial and
* provides conversion and validation of the fields in a particular calendar system.
*
* @return the chronology, never null
*/
public Chronology getChronology() {
return iChronology;
}
//-----------------------------------------------------------------------
/**
* Sets the value of the field at the specified index.
* <p>
* In version 2.0 and later, this method copies the array into the original.
* This is because the instance variable has been changed to be final to satisfy the Java Memory Model.
* This only impacts subclasses that are mutable.
*
* @param index the index
* @param value the value to set
* @throws IndexOutOfBoundsException if the index is invalid
*/
protected void setValue(int index, int value) {
DateTimeField field = getField(index);
int[] values = field.set(this, index, iValues, value);
System.arraycopy(values, 0, iValues, 0, iValues.length);
}
/**
* Sets the values of all fields.
* <p>
* In version 2.0 and later, this method copies the array into the original.
* This is because the instance variable has been changed to be final to satisfy the Java Memory Model.
* This only impacts subclasses that are mutable.
*
* @param values the array of values
*/
protected void setValues(int[] values) {
getChronology().validate(this, values);
System.arraycopy(values, 0, iValues, 0, iValues.length);
}
//-----------------------------------------------------------------------
/**
* Output the date using the specified format pattern.
*
* @param pattern the pattern specification, null means use <code>toString</code>
* @see org.joda
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>/*
* Copyright 2001-2011 Stephen Colebourne
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.joda.time;
/**
* Defines a partial time that does not support every datetime field, and is
* thus a local time.
* <p>
* A {@code ReadablePartial} supports a subset of those fields on the chronology.
* It cannot be compared to a {@code ReadableInstant}, as it does not fully
* specify an instant in time. The time it does specify is a local time, and does
* not include a time zone.
* <p>
* A {@code ReadablePartial} can be converted to a {@code ReadableInstant}
* using the {@code toDateTime} method. This works by providing a full base
* instant that can be used to 'fill in the gaps' and specify a time zone.
* <p>
* {@code ReadablePartial} is {@code Comparable} from v2.0.
* The comparison is based on the fields, compared in order, from largest to smallest.
* The first field that is non-equal is used to determine the result.
*
* @author Stephen Colebourne
* @since 1.0
*/
public interface ReadablePartial extends Comparable<ReadablePartial> {
/**
* Gets the number of fields that this partial supports.
*
* @return the number of fields supported
*/
int size();
/**
* Gets the field type at the specified index.
*
* @param index the index to retrieve
* @return the field at the specified index
* @throws IndexOutOfBoundsException if the index is invalid
*/
DateTimeFieldType getFieldType(int index);
/**
* Gets the field at the specified index.
*
* @param index the index to retrieve
* @return the field at the specified index
* @throws IndexOutOfBoundsException if the index is invalid
*/
DateTimeField getField(int index);
/**
* Gets the value at the specified index.
*
* @param index the index to retrieve
* @return the value of the field at the specified index
* @throws IndexOutOfBoundsException if the index is invalid
*/
int getValue(int index);
/**
* Gets the chronology of the partial which is never null.
* <p>
* The {@
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>link Chronology} is the calculation engine behind the partial and
* provides conversion and validation of the fields in a particular calendar system.
*
* @return the chronology, never null
*/
Chronology getChronology();
/**
* Gets the value of one of the fields.
* <p>
* The field type specified must be one of those that is supported by the partial.
*
* @param field a DateTimeFieldType instance that is supported by this partial
* @return the value of that field
* @throws IllegalArgumentException if the field is null or not supported
*/
int get(DateTimeFieldType field);
/**
* Checks whether the field type specified is supported by this partial.
*
* @param field the field to check, may be null which returns false
* @return true if the field is supported
*/
boolean isSupported(DateTimeFieldType field);
/**
* Converts this partial to a full datetime by resolving it against another
* datetime.
* <p>
* This method takes the specified datetime and sets the fields from this
* instant on top. The chronology from the base instant is used.
* <p>
* For example, if this partial represents a time, then the result of this
* method will be the datetime from the specified base instant plus the
* time from this partial.
*
* @param baseInstant the instant that provides the missing fields, null means now
* @return the combined datetime
*/
DateTime toDateTime(ReadableInstant baseInstant);
//-----------------------------------------------------------------------
/**
* Compares this partial with the specified object for equality based
* on the supported fields, chronology and values.
* <p>
* Two instances of ReadablePartial are equal if they have the same
* chronology, same field types (in same order) and same values.
*
* @param partial the object to compare to
* @return true if equal
*/
boolean equals(Object partial);
/**
* Gets a hash code for the partial that is compatible with the
* equals method.
* <p>
* The formula used must be:
* <pre>
* int total = 157;
* for (int i = 0; i < fields.length; i++) {
* total = 23 * total + values[i];
* total = 23 * total + fieldTypes[i].hashCode();
* }
* total += chronology.hashCode();
* return total;
* </pre>
*
* @return a suitable hash code
*/
int hashCode();
//-----------------------------------------------------------------------
// This is commented out to improve backwards compatibility
// /**
// * Compares this partial with another returning an integer
// * indicating the order.
// * <p>
// * The fields are compared in order, from largest to smallest.
// * The first field that is non-equal is used to determine the result
Time, 14
<FILEB>
<CHANGES>
if (partial.size() > 0 && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear()) && fieldIndex == 0) {
<CHANGEE>
<CHANGES>
int curMonth0 = partial.getValue(0) - 1;
int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
return set(partial, 0, values, newMonth);
}
<CHANGEE>
<FILEE>
<FILEB>
int i_yearToUse = (int)yearToUse;
int i_monthToUse = (int)monthToUse;
int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
if (dayToUse > maxDay) {
dayToUse = maxDay;
}
long datePart =
iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
return datePart + timePart;
}
//-----------------------------------------------------------------------
public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
// overridden as superclass algorithm can't handle
// 2004-02-29 + 48 months -> 2008-02-29 type dates
if (valueToAdd == 0) {
return values;
}
<CHANGES>
<CHANGEE>
// month is largest field and being added to, such as month-day
<CHANGES>
<CHANGEE>
if (DateTimeUtils.isContiguous(partial)) {
long instant = 0L;
for (int i = 0, isize = partial.size(); i < isize; i++) {
instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
}
instant = add(instant, valueToAdd);
return iChronology.get(partial, instant);
} else {
return super.add(partial, fieldIndex, values, valueToAdd);
}
}
//-----------------------------------------------------------------------
<FILEE>
<SCANS>2;
} else {
leapYears = relativeYear >> 2;
// For post 1687 an adjustment is needed as jan1st is before leap day
if (!isLeapYear(year)) {
leapYears++;
}
}
long millis = (relativeYear * 365L + leapYears)
* (long)DateTimeConstants.MILLIS_PER_DAY;
// Adjust to account for difference between 1687-01-01 and 1686-04-23.
return millis + (365L - 112) * DateTimeConstants.MILLIS_PER_DAY;
}
//-----------------------------------------------------------------------
int getMinYear() {
return MIN_YEAR;
}
//-----------------------------------------------------------------------
int getMaxYear() {
return MAX_YEAR;
}
//-----------------------------------------------------------------------
long getApproxMillisAtEpochDividedByTwo() {
return (1686L * MILLIS_PER_YEAR + 112L * DateTimeConstants.MILLIS_PER_DAY) / 2;
}
//-----------------------------------------------------------------------
protected void assemble(Fields fields) {
if (getBase() == null) {
super.assemble(fields);
// Coptic, like Julian, has no year zero.
fields.year = new SkipDateTimeField(this, fields.year);
fields.weekyear = new SkipDateTimeField(this, fields.weekyear);
fields.era = ERA_FIELD;
fields.monthOfYear = new BasicMonthOfYearDateTimeField(this, 13);
fields.months = fields.monthOfYear.getDurationField();
}
}
}